Skip to content

Commit d73756a

Browse files
committed
New feature
1 parent 4657510 commit d73756a

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

packages/node/src/integrations/childProcess.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ChildProcess } from 'node:child_process';
22
import * as diagnosticsChannel from 'node:diagnostics_channel';
33
import type { Worker } from 'node:worker_threads';
4-
import { addBreadcrumb, defineIntegration } from '@sentry/core';
4+
import { addBreadcrumb, captureException, defineIntegration } from '@sentry/core';
55

66
interface Options {
77
/**
@@ -10,6 +10,13 @@ interface Options {
1010
* @default false
1111
*/
1212
includeChildProcessArgs?: boolean;
13+
14+
/**
15+
* Whether to capture errors from worker threads.
16+
*
17+
* @default true
18+
*/
19+
captureWorkerErrors?: boolean;
1320
}
1421

1522
const INTEGRATION_NAME = 'ChildProcess';
@@ -29,7 +36,7 @@ export const childProcessIntegration = defineIntegration((options: Options = {})
2936

3037
diagnosticsChannel.channel('worker_threads').subscribe((event: unknown) => {
3138
if (event && typeof event === 'object' && 'worker' in event) {
32-
captureWorkerThreadEvents(event.worker as Worker);
39+
captureWorkerThreadEvents(event.worker as Worker, options);
3340
}
3441
});
3542
},
@@ -82,19 +89,25 @@ function captureChildProcessEvents(child: ChildProcess, options: Options): void
8289
});
8390
}
8491

85-
function captureWorkerThreadEvents(worker: Worker): void {
92+
function captureWorkerThreadEvents(worker: Worker, options: Options): void {
8693
let threadId: number | undefined;
8794

8895
worker
8996
.on('online', () => {
9097
threadId = worker.threadId;
9198
})
9299
.on('error', error => {
93-
addBreadcrumb({
94-
category: 'worker_thread',
95-
message: `Worker thread errored with '${error.message}'`,
96-
level: 'error',
97-
data: { threadId },
98-
});
100+
if (options.captureWorkerErrors !== false) {
101+
captureException(error, {
102+
mechanism: { type: 'instrument', handled: false, data: { threadId: String(threadId) } },
103+
});
104+
} else {
105+
addBreadcrumb({
106+
category: 'worker_thread',
107+
message: `Worker thread errored with '${error.message}'`,
108+
level: 'error',
109+
data: { threadId },
110+
});
111+
}
99112
});
100113
}

0 commit comments

Comments
 (0)