Skip to content

Commit d396241

Browse files
authored
feat(node): Add breadcrumbs for child_process and worker_thread (#13896)
1 parent a7193fb commit d396241

File tree

13 files changed

+748
-3
lines changed

13 files changed

+748
-3
lines changed

dev-packages/e2e-tests/test-applications/node-exports-test-app/scripts/consistentExports.ts

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ const DEPENDENTS: Dependent[] = [
5050
ignoreExports: [
5151
// not supported in bun:
5252
'NodeClient',
53+
// Bun doesn't emit the required diagnostics_channel events
54+
'processThreadBreadcrumbIntegration',
5355
],
5456
},
5557
{

dev-packages/node-integration-tests/suites/anr/test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ const ANR_EVENT_WITH_SCOPE = {
5656
user: {
5757
5858
},
59-
breadcrumbs: [
59+
breadcrumbs: expect.arrayContaining([
6060
{
6161
timestamp: expect.any(Number),
6262
message: 'important message!',
6363
},
64-
],
64+
]),
6565
};
6666

6767
conditionalTest({ min: 16 })('should report ANR when event loop blocked', () => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { spawn } from 'child_process';
2+
import { join } from 'path';
3+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
4+
import * as Sentry from '@sentry/node';
5+
import { Worker } from 'worker_threads';
6+
7+
const __dirname = new URL('.', import.meta.url).pathname;
8+
9+
Sentry.init({
10+
dsn: 'https://[email protected]/1337',
11+
release: '1.0',
12+
transport: loggingTransport,
13+
});
14+
15+
await new Promise(resolve => {
16+
const child = spawn('sleep', ['a']);
17+
child.on('error', resolve);
18+
child.on('exit', resolve);
19+
});
20+
21+
await new Promise(resolve => {
22+
const worker = new Worker(join(__dirname, 'worker.mjs'));
23+
worker.on('error', resolve);
24+
worker.on('exit', resolve);
25+
});
26+
27+
throw new Error('This is a test error');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import type { Event } from '@sentry/types';
2+
import { conditionalTest } from '../../../utils';
3+
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';
4+
5+
const EVENT = {
6+
// and an exception that is our ANR
7+
exception: {
8+
values: [
9+
{
10+
type: 'Error',
11+
value: 'This is a test error',
12+
},
13+
],
14+
},
15+
breadcrumbs: [
16+
{
17+
timestamp: expect.any(Number),
18+
category: 'child_process',
19+
message: "Child process exited with code '1'",
20+
level: 'warning',
21+
data: {
22+
spawnfile: 'sleep',
23+
},
24+
},
25+
{
26+
timestamp: expect.any(Number),
27+
category: 'worker_thread',
28+
message: "Worker thread errored with 'Worker error'",
29+
level: 'error',
30+
data: {
31+
threadId: expect.any(Number),
32+
},
33+
},
34+
],
35+
};
36+
37+
conditionalTest({ min: 20 })('should capture process and thread breadcrumbs', () => {
38+
afterAll(() => {
39+
cleanupChildProcesses();
40+
});
41+
42+
test('ESM', done => {
43+
createRunner(__dirname, 'app.mjs')
44+
.withMockSentryServer()
45+
.expect({ event: EVENT as Event })
46+
.start(done);
47+
});
48+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
throw new Error('Worker error');

packages/astro/src/index.server.ts

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export {
8989
parameterize,
9090
postgresIntegration,
9191
prismaIntegration,
92+
processThreadBreadcrumbIntegration,
9293
redisIntegration,
9394
requestDataIntegration,
9495
rewriteFramesIntegration,

packages/aws-serverless/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export {
102102
setupNestErrorHandler,
103103
postgresIntegration,
104104
prismaIntegration,
105+
processThreadBreadcrumbIntegration,
105106
hapiIntegration,
106107
setupHapiErrorHandler,
107108
spotlightIntegration,

packages/google-cloud-serverless/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export {
114114
zodErrorsIntegration,
115115
profiler,
116116
amqplibIntegration,
117+
processThreadBreadcrumbIntegration,
117118
} from '@sentry/node';
118119

119120
export {

packages/node/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export { spotlightIntegration } from './integrations/spotlight';
3131
export { genericPoolIntegration } from './integrations/tracing/genericPool';
3232
export { dataloaderIntegration } from './integrations/tracing/dataloader';
3333
export { amqplibIntegration } from './integrations/tracing/amqplib';
34+
export { processThreadBreadcrumbIntegration } from './integrations/processThread';
3435

3536
export { SentryContextManager } from './otel/contextManager';
3637
export { generateInstrumentOnce } from './otel/instrument';

0 commit comments

Comments
 (0)