Skip to content

Commit 9df69b1

Browse files
committed
Include spawn calls & their (sanitized) args in error reports
1 parent 4782a12 commit 9df69b1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/error-tracking.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as child_process from 'child_process';
12
import * as Sentry from '@sentry/node';
23
import { IS_PROD_BUILD } from './util';
34

@@ -46,6 +47,25 @@ export function initErrorTracking() {
4647
scope.setTag('platform', process.platform);
4748
});
4849

50+
// Include breadcrumbs for subprocess spawning, to trace interceptor startup details:
51+
const rawSpawn = child_process.spawn;
52+
(child_process as any).spawn = function (command: any, args?: any, options?: { [key: string]: string }) {
53+
const sanitizedOptions = { ...options,
54+
env: Object.entries((options && options.env) || {})
55+
.map(([key, value]) => {
56+
// Remove all actual env values from this reporting; only included our changed values.
57+
const realValue = process.env[key];
58+
if (value === realValue) return undefined;
59+
else if (realValue) return [key, value.replace(realValue, '[...]')];
60+
else return [key, value];
61+
})
62+
.filter((entry) => entry !== undefined)
63+
};
64+
65+
addBreadcrumb('Spawning process', { data: { command, args, options: sanitizedOptions } });
66+
return rawSpawn.apply(this, arguments);
67+
};
68+
4969
sentryInitialized = true;
5070
}
5171
}

0 commit comments

Comments
 (0)