Skip to content

Commit f2e621a

Browse files
authored
ref(node-core): Adjust mechanism of onUnhandledRejection and onUnhandledException integrations (#17636)
mechanism type now follows the trace origin-esque naming, similarly to global handlers [in browser](https://github.com/getsentry/sentry-javascript/blob/4b562bcbf0a81494627ab2c5a153ddbddb2d89ae/packages/browser/src/integrations/globalhandlers.ts#L101) ref #17212
1 parent 7200e63 commit f2e621a

File tree

11 files changed

+81
-8
lines changed

11 files changed

+81
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- ref(node): Adjust mechanism of express, hapi and fastify error handlers ([#17623](https://github.com/getsentry/sentry-javascript/pull/17623))
2727
- ref(node-core): Add `mechanism` to cron instrumentations ([#17544](https://github.com/getsentry/sentry-javascript/pull/17544))
2828
- ref(node-core): Add more specific `mechanism.type` to worker thread errors from `childProcessIntegration` ([#17578](https://github.com/getsentry/sentry-javascript/pull/17578))
29+
- ref(node-core): Adjust `mechanism` of `onUnhandledRejection` and `onUnhandledException` integrations ([#17636](https://github.com/getsentry/sentry-javascript/pull/17636))
2930
- ref(node): Add mechanism to errors captured via connect and koa integrations ([#17579](https://github.com/getsentry/sentry-javascript/pull/17579))
3031
- ref(nuxt): Add and adjust `mechanism.type` in error events ([#17599](https://github.com/getsentry/sentry-javascript/pull/17599))
3132
- ref(react): Add mechanism to `reactErrorHandler` and adjust mechanism in `ErrorBoundary` ([#17602](https://github.com/getsentry/sentry-javascript/pull/17602))

dev-packages/node-core-integration-tests/suites/cron/node-schedule/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ test('node-schedule instrumentation', async () => {
7474
{
7575
type: 'Error',
7676
value: 'Error in cron job',
77-
mechanism: { type: 'onunhandledrejection', handled: false },
77+
mechanism: { type: 'auto.node.onunhandledrejection', handled: false },
7878
},
7979
],
8080
},
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const Sentry = require('@sentry/node');
2+
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
3+
4+
Sentry.init({
5+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
6+
transport: loggingTransport,
7+
});
8+
9+
throw new Error('foo');

dev-packages/node-core-integration-tests/suites/public-api/OnUncaughtException/test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as childProcess from 'child_process';
22
import * as path from 'path';
33
import { describe, expect, test } from 'vitest';
4+
import { createRunner } from '../../../utils/runner';
45

56
describe('OnUncaughtException integration', () => {
67
test('should close process on uncaught error with no additional listeners registered', () =>
@@ -74,4 +75,30 @@ describe('OnUncaughtException integration', () => {
7475
});
7576
}));
7677
});
78+
79+
test('sets correct event mechanism', async () => {
80+
await createRunner(__dirname, 'basic.js')
81+
.expect({
82+
event: {
83+
level: 'fatal',
84+
exception: {
85+
values: [
86+
{
87+
type: 'Error',
88+
value: 'foo',
89+
mechanism: {
90+
type: 'auto.node.onuncaughtexception',
91+
handled: false,
92+
},
93+
stacktrace: {
94+
frames: expect.any(Array),
95+
},
96+
},
97+
],
98+
},
99+
},
100+
})
101+
.start()
102+
.completed();
103+
});
77104
});

dev-packages/node-core-integration-tests/suites/public-api/onUnhandledRejectionIntegration/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ test rejection`);
8383
type: 'Error',
8484
value: 'test rejection',
8585
mechanism: {
86-
type: 'onunhandledrejection',
86+
type: 'auto.node.onunhandledrejection',
8787
handled: false,
8888
},
8989
stacktrace: {
@@ -109,7 +109,7 @@ test rejection`);
109109
type: 'Error',
110110
value: 'test rejection',
111111
mechanism: {
112-
type: 'onunhandledrejection',
112+
type: 'auto.node.onunhandledrejection',
113113
handled: false,
114114
},
115115
stacktrace: {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const Sentry = require('@sentry/node');
2+
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
3+
4+
Sentry.init({
5+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
6+
transport: loggingTransport,
7+
});
8+
9+
throw new Error('foo');

dev-packages/node-integration-tests/suites/public-api/OnUncaughtException/test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as childProcess from 'child_process';
22
import * as path from 'path';
33
import { describe, expect, test } from 'vitest';
4+
import { createRunner } from '../../../utils/runner';
45

56
describe('OnUncaughtException integration', () => {
67
test('should close process on uncaught error with no additional listeners registered', () =>
@@ -74,4 +75,30 @@ describe('OnUncaughtException integration', () => {
7475
});
7576
}));
7677
});
78+
79+
test('sets correct event mechanism', async () => {
80+
await createRunner(__dirname, 'basic.js')
81+
.expect({
82+
event: {
83+
level: 'fatal',
84+
exception: {
85+
values: [
86+
{
87+
type: 'Error',
88+
value: 'foo',
89+
mechanism: {
90+
type: 'auto.node.onuncaughtexception',
91+
handled: false,
92+
},
93+
stacktrace: {
94+
frames: expect.any(Array),
95+
},
96+
},
97+
],
98+
},
99+
},
100+
})
101+
.start()
102+
.completed();
103+
});
77104
});

dev-packages/node-integration-tests/suites/public-api/onUnhandledRejectionIntegration/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ test rejection`);
8484
type: 'Error',
8585
value: 'test rejection',
8686
mechanism: {
87-
type: 'onunhandledrejection',
87+
type: 'auto.node.onunhandledrejection',
8888
handled: false,
8989
},
9090
stacktrace: {
@@ -110,7 +110,7 @@ test rejection`);
110110
type: 'Error',
111111
value: 'test rejection',
112112
mechanism: {
113-
type: 'onunhandledrejection',
113+
type: 'auto.node.onunhandledrejection',
114114
handled: false,
115115
},
116116
stacktrace: {

packages/core/test/lib/integrations/eventFilters.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ const USELESS_EXCEPTION_EVENT: Event = {
256256
values: [
257257
{},
258258
{
259-
mechanism: { type: 'onunhandledrejection', handled: false },
259+
mechanism: { type: 'auto.node.onunhandledrejection', handled: false },
260260
},
261261
],
262262
},

packages/node-core/src/integrations/onuncaughtexception.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export function makeErrorHandler(client: NodeClient, options: OnUncaughtExceptio
108108
},
109109
mechanism: {
110110
handled: false,
111-
type: 'onuncaughtexception',
111+
type: 'auto.node.onuncaughtexception',
112112
},
113113
});
114114
}

0 commit comments

Comments
 (0)