File tree 1 file changed +16
-2
lines changed
1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,19 @@ export function getCpus(): string {
53
53
54
54
const homeDir = os . homedir ( ) ;
55
55
56
+ const sanitizeError = ( err : Error ) : Error => {
57
+ if ( err . name ) {
58
+ err . name = err . name . replace ( homeDir , '~' ) ;
59
+ }
60
+ if ( err . message ) {
61
+ err . message = err . message . replace ( homeDir , '~' ) ;
62
+ }
63
+ if ( err . stack ) {
64
+ // there might be lots of this one
65
+ err . stack = err . stack . replace ( new RegExp ( `\\b${ homeDir } \\b` , 'gi' ) , '~' ) ;
66
+ }
67
+ return err ;
68
+ } ;
56
69
function getSystemMemory ( ) : string {
57
70
return `${ ( os . totalmem ( ) / ( 1024 * 1024 * 1024 ) ) . toFixed ( 2 ) } GB` ;
58
71
}
@@ -136,9 +149,10 @@ export class AppInsights extends AsyncCreatable<TelemetryOptions> {
136
149
* @param attributes {Attributes} - map of measurements to publish alongside the exception.
137
150
*/
138
151
public sendTelemetryException ( exception : Error , attributes : Attributes = { } ) : void {
139
- this . logger . debug ( `Sending telemetry exception: ${ exception . message } ` ) ;
152
+ const cleanException = sanitizeError ( exception ) ;
153
+ this . logger . debug ( `Sending telemetry exception: ${ cleanException . message } ` ) ;
140
154
const { properties, measurements } = buildPropertiesAndMeasurements ( attributes ) ;
141
- this . appInsightsClient . trackException ( { exception, properties, measurements } ) ;
155
+ this . appInsightsClient . trackException ( { exception : cleanException , properties, measurements } ) ;
142
156
}
143
157
144
158
/**
You can’t perform that action at this time.
0 commit comments