From 6d1ab2ef9363c8ff488a74a9de79f964b5a4951e Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Mon, 15 Sep 2025 12:22:18 +0200 Subject: [PATCH 1/2] ref(node-core): Adjust `mechanism` of `onUnhandledRejection` and `onUnhandledException` integrations --- .../suites/cron/node-schedule/test.ts | 2 +- .../public-api/OnUncaughtException/basic.js | 9 +++++++ .../public-api/OnUncaughtException/test.ts | 27 +++++++++++++++++++ .../onUnhandledRejectionIntegration/test.ts | 4 +-- .../public-api/OnUncaughtException/basic.js | 9 +++++++ .../public-api/OnUncaughtException/test.ts | 27 +++++++++++++++++++ .../onUnhandledRejectionIntegration/test.ts | 4 +-- .../lib/integrations/eventFilters.test.ts | 2 +- .../src/integrations/onuncaughtexception.ts | 2 +- .../src/integrations/onunhandledrejection.ts | 2 +- 10 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 dev-packages/node-core-integration-tests/suites/public-api/OnUncaughtException/basic.js create mode 100644 dev-packages/node-integration-tests/suites/public-api/OnUncaughtException/basic.js diff --git a/dev-packages/node-core-integration-tests/suites/cron/node-schedule/test.ts b/dev-packages/node-core-integration-tests/suites/cron/node-schedule/test.ts index 19d2d0b4e339..285e41cee304 100644 --- a/dev-packages/node-core-integration-tests/suites/cron/node-schedule/test.ts +++ b/dev-packages/node-core-integration-tests/suites/cron/node-schedule/test.ts @@ -74,7 +74,7 @@ test('node-schedule instrumentation', async () => { { type: 'Error', value: 'Error in cron job', - mechanism: { type: 'onunhandledrejection', handled: false }, + mechanism: { type: 'auto.node.onunhandledrejection', handled: false }, }, ], }, diff --git a/dev-packages/node-core-integration-tests/suites/public-api/OnUncaughtException/basic.js b/dev-packages/node-core-integration-tests/suites/public-api/OnUncaughtException/basic.js new file mode 100644 index 000000000000..656a5b19220b --- /dev/null +++ b/dev-packages/node-core-integration-tests/suites/public-api/OnUncaughtException/basic.js @@ -0,0 +1,9 @@ +const Sentry = require('@sentry/node'); +const { loggingTransport } = require('@sentry-internal/node-integration-tests'); + +Sentry.init({ + dsn: 'https://public@dsn.ingest.sentry.io/1337', + transport: loggingTransport, +}); + +throw new Error('foo'); diff --git a/dev-packages/node-core-integration-tests/suites/public-api/OnUncaughtException/test.ts b/dev-packages/node-core-integration-tests/suites/public-api/OnUncaughtException/test.ts index d27b08f152be..5a35991bfd4b 100644 --- a/dev-packages/node-core-integration-tests/suites/public-api/OnUncaughtException/test.ts +++ b/dev-packages/node-core-integration-tests/suites/public-api/OnUncaughtException/test.ts @@ -1,6 +1,7 @@ import * as childProcess from 'child_process'; import * as path from 'path'; import { describe, expect, test } from 'vitest'; +import { createRunner } from '../../../utils/runner'; describe('OnUncaughtException integration', () => { test('should close process on uncaught error with no additional listeners registered', () => @@ -74,4 +75,30 @@ describe('OnUncaughtException integration', () => { }); })); }); + + test('sets correct event mechanism', async () => { + await createRunner(__dirname, 'basic.js') + .expect({ + event: { + level: 'fatal', + exception: { + values: [ + { + type: 'Error', + value: 'foo', + mechanism: { + type: 'auto.node.onuncaughtexception', + handled: false, + }, + stacktrace: { + frames: expect.any(Array), + }, + }, + ], + }, + }, + }) + .start() + .completed(); + }); }); diff --git a/dev-packages/node-core-integration-tests/suites/public-api/onUnhandledRejectionIntegration/test.ts b/dev-packages/node-core-integration-tests/suites/public-api/onUnhandledRejectionIntegration/test.ts index 2f4a22c835a4..8ee873a4f017 100644 --- a/dev-packages/node-core-integration-tests/suites/public-api/onUnhandledRejectionIntegration/test.ts +++ b/dev-packages/node-core-integration-tests/suites/public-api/onUnhandledRejectionIntegration/test.ts @@ -83,7 +83,7 @@ test rejection`); type: 'Error', value: 'test rejection', mechanism: { - type: 'onunhandledrejection', + type: 'auto.node.onunhandledrejection', handled: false, }, stacktrace: { @@ -109,7 +109,7 @@ test rejection`); type: 'Error', value: 'test rejection', mechanism: { - type: 'onunhandledrejection', + type: 'auto.node.onunhandledrejection', handled: false, }, stacktrace: { diff --git a/dev-packages/node-integration-tests/suites/public-api/OnUncaughtException/basic.js b/dev-packages/node-integration-tests/suites/public-api/OnUncaughtException/basic.js new file mode 100644 index 000000000000..656a5b19220b --- /dev/null +++ b/dev-packages/node-integration-tests/suites/public-api/OnUncaughtException/basic.js @@ -0,0 +1,9 @@ +const Sentry = require('@sentry/node'); +const { loggingTransport } = require('@sentry-internal/node-integration-tests'); + +Sentry.init({ + dsn: 'https://public@dsn.ingest.sentry.io/1337', + transport: loggingTransport, +}); + +throw new Error('foo'); diff --git a/dev-packages/node-integration-tests/suites/public-api/OnUncaughtException/test.ts b/dev-packages/node-integration-tests/suites/public-api/OnUncaughtException/test.ts index d27b08f152be..5a35991bfd4b 100644 --- a/dev-packages/node-integration-tests/suites/public-api/OnUncaughtException/test.ts +++ b/dev-packages/node-integration-tests/suites/public-api/OnUncaughtException/test.ts @@ -1,6 +1,7 @@ import * as childProcess from 'child_process'; import * as path from 'path'; import { describe, expect, test } from 'vitest'; +import { createRunner } from '../../../utils/runner'; describe('OnUncaughtException integration', () => { test('should close process on uncaught error with no additional listeners registered', () => @@ -74,4 +75,30 @@ describe('OnUncaughtException integration', () => { }); })); }); + + test('sets correct event mechanism', async () => { + await createRunner(__dirname, 'basic.js') + .expect({ + event: { + level: 'fatal', + exception: { + values: [ + { + type: 'Error', + value: 'foo', + mechanism: { + type: 'auto.node.onuncaughtexception', + handled: false, + }, + stacktrace: { + frames: expect.any(Array), + }, + }, + ], + }, + }, + }) + .start() + .completed(); + }); }); diff --git a/dev-packages/node-integration-tests/suites/public-api/onUnhandledRejectionIntegration/test.ts b/dev-packages/node-integration-tests/suites/public-api/onUnhandledRejectionIntegration/test.ts index 468e66a058ca..d3c8b4d599ff 100644 --- a/dev-packages/node-integration-tests/suites/public-api/onUnhandledRejectionIntegration/test.ts +++ b/dev-packages/node-integration-tests/suites/public-api/onUnhandledRejectionIntegration/test.ts @@ -84,7 +84,7 @@ test rejection`); type: 'Error', value: 'test rejection', mechanism: { - type: 'onunhandledrejection', + type: 'auto.node.onunhandledrejection', handled: false, }, stacktrace: { @@ -110,7 +110,7 @@ test rejection`); type: 'Error', value: 'test rejection', mechanism: { - type: 'onunhandledrejection', + type: 'auto.node.onunhandledrejection', handled: false, }, stacktrace: { diff --git a/packages/core/test/lib/integrations/eventFilters.test.ts b/packages/core/test/lib/integrations/eventFilters.test.ts index d78b59ede112..a107efe17719 100644 --- a/packages/core/test/lib/integrations/eventFilters.test.ts +++ b/packages/core/test/lib/integrations/eventFilters.test.ts @@ -256,7 +256,7 @@ const USELESS_EXCEPTION_EVENT: Event = { values: [ {}, { - mechanism: { type: 'onunhandledrejection', handled: false }, + mechanism: { type: 'auto.node.onunhandledrejection', handled: false }, }, ], }, diff --git a/packages/node-core/src/integrations/onuncaughtexception.ts b/packages/node-core/src/integrations/onuncaughtexception.ts index 045e2e9f7736..41c4bf96917d 100644 --- a/packages/node-core/src/integrations/onuncaughtexception.ts +++ b/packages/node-core/src/integrations/onuncaughtexception.ts @@ -108,7 +108,7 @@ export function makeErrorHandler(client: NodeClient, options: OnUncaughtExceptio }, mechanism: { handled: false, - type: 'onuncaughtexception', + type: 'auto.node.onuncaughtexception', }, }); } diff --git a/packages/node-core/src/integrations/onunhandledrejection.ts b/packages/node-core/src/integrations/onunhandledrejection.ts index a11d5c3cf7b0..dbddb2a4c396 100644 --- a/packages/node-core/src/integrations/onunhandledrejection.ts +++ b/packages/node-core/src/integrations/onunhandledrejection.ts @@ -69,7 +69,7 @@ export function makeUnhandledPromiseHandler( }, mechanism: { handled: false, - type: 'onunhandledrejection', + type: 'auto.node.onunhandledrejection', }, }); }); From 704e2373ea3840f3d3087a96bdb3adaec80d77d1 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Mon, 15 Sep 2025 12:27:54 +0200 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cbb0281ac31..3386a85c1bbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - ref(node): Adjust mechanism of express, hapi and fastify error handlers ([#17623](https://github.com/getsentry/sentry-javascript/pull/17623)) - ref(node-core): Add `mechanism` to cron instrumentations ([#17544](https://github.com/getsentry/sentry-javascript/pull/17544)) - ref(node-core): Add more specific `mechanism.type` to worker thread errors from `childProcessIntegration` ([#17578](https://github.com/getsentry/sentry-javascript/pull/17578)) + - ref(node-core): Adjust `mechanism` of `onUnhandledRejection` and `onUnhandledException` integrations ([#17636](https://github.com/getsentry/sentry-javascript/pull/17636)) - ref(node): Add mechanism to errors captured via connect and koa integrations ([#17579](https://github.com/getsentry/sentry-javascript/pull/17579)) - ref(nuxt): Add and adjust `mechanism.type` in error events ([#17599](https://github.com/getsentry/sentry-javascript/pull/17599)) - ref(react): Add mechanism to `reactErrorHandler` and adjust mechanism in `ErrorBoundary` ([#17602](https://github.com/getsentry/sentry-javascript/pull/17602))