Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Sentry.init({
traceLifecycle: 'static',
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
integrations: [Sentry.childProcessIntegration({ captureWorkerErrors: false })],
integrations: [Sentry.childProcessIntegration(), Sentry.workerIntegration({ captureWorkerErrors: false })],
transport: loggingTransport,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const WORKER_EVENT: Event = {
type: 'Error',
value: 'Test error',
mechanism: {
type: 'auto.child_process.worker_thread',
type: 'auto.worker_thread',
handled: false,
data: {
threadId: expect.any(String),
Expand Down
1 change: 1 addition & 0 deletions packages/aws-serverless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export {
processSessionIntegration,
prismaIntegration,
childProcessIntegration,
workerIntegration,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing Astro workerIntegration export

Medium Severity

workerIntegration is exported from @sentry/node, @sentry/aws-serverless, and @sentry/google-cloud-serverless, but @sentry/astro still only re-exports childProcessIntegration. Astro users cannot access the new API, and the consistent-exports check will fail for @sentry/astro.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 26c387c. Configure here.

createSentryWinstonTransport,
hapiIntegration,
setupHapiErrorHandler,
Expand Down
1 change: 1 addition & 0 deletions packages/google-cloud-serverless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export {
anthropicAIIntegration,
googleGenAIIntegration,
childProcessIntegration,
workerIntegration,
createSentryWinstonTransport,
vercelAIIntegration,
logger,
Expand Down
1 change: 1 addition & 0 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export { metrics, withStreamedSpan } from '@sentry/core';
export * as logger from './logs/exports';

export { childProcessIntegration } from './integrations/childProcess';
export { workerIntegration } from './integrations/workerIntegration';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bun export check missing ignore

Medium Severity

workerIntegration is a new @sentry/node export, but Bun already ignores childProcessIntegration as unsupported and does not ignore workerIntegration. The consistent-exports e2e check will treat the new export as missing from @sentry/bun and fail.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 26c387c. Configure here.

export { consoleIntegration } from './integrations/console';
export { nodeContextIntegration } from './integrations/context';
export { contextLinesIntegration } from './integrations/contextlines';
Expand Down
43 changes: 8 additions & 35 deletions packages/node/src/integrations/childProcess.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { ChildProcess } from 'node:child_process';
import * as diagnosticsChannel from 'node:diagnostics_channel';
import type { Worker } from 'node:worker_threads';
import { addBreadcrumb, captureException, defineIntegration, isObjectLike } from '@sentry/core';
Comment thread
cursor[bot] marked this conversation as resolved.
import { addBreadcrumb, defineIntegration, isObjectLike } from '@sentry/core';

interface Options {
/**
Expand All @@ -12,17 +11,19 @@ interface Options {
includeChildProcessArgs?: boolean;

/**
* Whether to capture errors from worker threads.
*
* @default true
* @deprecated This option has been moved to `workerIntegration()`.
* Use `workerIntegration({ captureWorkerErrors: false })` instead.
* This option is now a no-op and will be removed in a future version.
*/
captureWorkerErrors?: boolean;
}

const INTEGRATION_NAME = 'ChildProcess' as const;

/**
* Capture breadcrumbs and events for child processes and worker threads.
* Capture breadcrumbs and events for child processes.
*
* For worker thread events, use `workerIntegration()` instead.
*/
export const childProcessIntegration = defineIntegration((options: Options = {}) => {
return {
Comment thread
sentry[bot] marked this conversation as resolved.
Expand All @@ -33,12 +34,6 @@ export const childProcessIntegration = defineIntegration((options: Options = {})
captureChildProcessEvents(event.process as ChildProcess, options);
}
});

diagnosticsChannel.channel('worker_threads').subscribe((event: unknown) => {
if (isObjectLike(event) && 'worker' in event) {
captureWorkerThreadEvents(event.worker as Worker, options);
}
});
},
};
});
Expand Down Expand Up @@ -69,7 +64,7 @@ function captureChildProcessEvents(child: ChildProcess, options: Options): void
addBreadcrumb({
category: 'child_process',
message: `Child process exited with code '${code}'`,
level: code === 0 ? 'info' : 'warning',
level: 'warning',
data,
});
}
Expand All @@ -89,25 +84,3 @@ function captureChildProcessEvents(child: ChildProcess, options: Options): void
});
}

function captureWorkerThreadEvents(worker: Worker, options: Options): void {
let threadId: number | undefined;

worker
.on('online', () => {
threadId = worker.threadId;
})
.on('error', error => {
if (options.captureWorkerErrors !== false) {
captureException(error, {
mechanism: { type: 'auto.child_process.worker_thread', handled: false, data: { threadId: String(threadId) } },
});
} else {
addBreadcrumb({
category: 'worker_thread',
message: `Worker thread errored with '${error.message}'`,
level: 'error',
data: { threadId },
});
}
});
}
53 changes: 53 additions & 0 deletions packages/node/src/integrations/workerIntegration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { Worker } from 'node:worker_threads';
import * as diagnosticsChannel from 'node:diagnostics_channel';
import { addBreadcrumb, captureException, defineIntegration, isObjectLike } from '@sentry/core';

interface Options {
/**
* Whether to capture errors from worker threads.
*
* @default true
*/
captureWorkerErrors?: boolean;
}

const INTEGRATION_NAME = 'Worker' as const;

/**
* Capture breadcrumbs and events for worker threads.
*/
export const workerIntegration = defineIntegration((options: Options = {}) => {
return {
name: INTEGRATION_NAME,
setup() {
diagnosticsChannel.channel('worker_threads').subscribe((event: unknown) => {
if (isObjectLike(event) && 'worker' in event) {
captureWorkerThreadEvents(event.worker as Worker, options);
}
});
},
};
});

function captureWorkerThreadEvents(worker: Worker, options: Options): void {
let threadId: number | undefined;

worker
.on('online', () => {
threadId = worker.threadId;
})
.on('error', error => {
if (options.captureWorkerErrors !== false) {
captureException(error, {
mechanism: { type: 'auto.worker_thread', handled: false, data: { threadId: threadId !== undefined ? String(threadId) : undefined } },

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale worker mechanism in tests

Medium Severity

workerIntegration now reports mechanism type auto.worker_thread, and child-process/test.ts was updated, but OnUncaughtException worker-thread tests still expect auto.child_process.worker_thread. Those suites use default integrations, so they will fail against the new mechanism. This was flagged because the review rules require feat PR tests to cover the newly added behavior.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 26c387c. Configure here.

});
} else {
addBreadcrumb({
category: 'worker_thread',
message: `Worker thread errored with '${error.message}'`,
level: 'error',
data: { threadId },
});
}
});
}
2 changes: 2 additions & 0 deletions packages/node/src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { detectOrchestrionSetup } from '@sentry/server-utils/orchestrion';
import { registerDiagnosticsChannelInjection } from '@sentry/server-utils/orchestrion/register';
import { DEBUG_BUILD } from '../debug-build';
import { childProcessIntegration } from '../integrations/childProcess';
import { workerIntegration } from '../integrations/workerIntegration';
import { consoleIntegration } from '../integrations/console';
import { nodeContextIntegration } from '../integrations/context';
import { contextLinesIntegration } from '../integrations/contextlines';
Expand Down Expand Up @@ -68,6 +69,7 @@ function getBaseDefaultIntegrations(): Integration[] {
localVariablesIntegration(),
nodeContextIntegration(),
childProcessIntegration(),
workerIntegration(),
processSessionIntegration(),
modulesIntegration(),
];
Expand Down