Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit af69b45

Browse files
authored
ref(nestjs): Add mechanism to captured errors (#17312)
The NestJS SDK didn't add a mechanism to a bunch of caught errors. This resulted in the errors being incorrectly marked as `handled: true` and the `mechansim.type` defaulting to `'generic'`. This patch: - adds the mechanism to all `captureException` calls within the SDK, marking caught exceptions as `handled: false` - reviewers: Please let me know if any of these should in fact be `handled: true`! - adds a specific `mechanism.type`, following the naming scheme of [trace origin](https://develop.sentry.dev/sdk/telemetry/traces/trace-origin/) - adjusts and adds test assertions so that we actually test on the expected mechanism
1 parent 8e0ad60 commit af69b45

File tree

18 files changed

+136
-12
lines changed

18 files changed

+136
-12
lines changed

‎dev-packages/e2e-tests/test-applications/nestjs-11/tests/cron-decorator.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ test('Sends exceptions to Sentry on error in cron job', async ({ baseURL }) => {
7171

7272
expect(errorEvent.exception?.values).toHaveLength(1);
7373
expect(errorEvent.exception?.values?.[0]?.value).toBe('Test error from cron job');
74+
expect(errorEvent.exception?.values?.[0]?.mechanism).toEqual({
75+
handled: false,
76+
type: 'auto.cron.nestjs.async',
77+
});
78+
7479
expect(errorEvent.contexts?.trace).toEqual({
7580
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
7681
span_id: expect.stringMatching(/[a-f0-9]{16}/),

‎dev-packages/e2e-tests/test-applications/nestjs-11/tests/errors.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ test('Sends exception to Sentry', async ({ baseURL }) => {
1313

1414
expect(errorEvent.exception?.values).toHaveLength(1);
1515
expect(errorEvent.exception?.values?.[0]?.value).toBe('This is an exception with id 123');
16+
expect(errorEvent.exception?.values?.[0]?.mechanism).toEqual({
17+
handled: false,
18+
type: 'auto.http.nestjs.global_filter',
19+
});
1620

1721
expect(errorEvent.request).toEqual({
1822
method: 'GET',

‎dev-packages/e2e-tests/test-applications/nestjs-8/tests/errors.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ test('Sends exception to Sentry', async ({ baseURL }) => {
1313

1414
expect(errorEvent.exception?.values).toHaveLength(1);
1515
expect(errorEvent.exception?.values?.[0]?.value).toBe('This is an exception with id 123');
16+
expect(errorEvent.exception?.values?.[0]?.mechanism).toEqual({
17+
handled: false,
18+
type: 'auto.http.nestjs.global_filter',
19+
});
1620

1721
expect(errorEvent.request).toEqual({
1822
method: 'GET',

‎dev-packages/e2e-tests/test-applications/nestjs-basic-with-graphql/tests/errors.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ test('Sends exception to Sentry', async ({ baseURL }) => {
1414
expect(errorEvent.exception?.values).toHaveLength(1);
1515
expect(errorEvent.exception?.values?.[0]?.value).toBe('This is an exception with id 123');
1616

17+
expect(errorEvent.exception?.values?.[0]?.mechanism).toEqual({
18+
handled: false,
19+
type: 'auto.http.nestjs.global_filter',
20+
});
21+
1722
expect(errorEvent.request).toEqual({
1823
method: 'GET',
1924
cookies: {},
@@ -102,6 +107,11 @@ test('Sends graphql exception to Sentry', async ({ baseURL }) => {
102107
expect(errorEvent.exception?.values).toHaveLength(1);
103108
expect(errorEvent.exception?.values?.[0]?.value).toBe('This is an exception!');
104109

110+
expect(errorEvent.exception?.values?.[0]?.mechanism).toEqual({
111+
handled: false,
112+
type: 'auto.graphql.nestjs.global_filter',
113+
});
114+
105115
expect(errorEvent.request).toEqual({
106116
method: 'POST',
107117
cookies: {},

‎dev-packages/e2e-tests/test-applications/nestjs-basic/tests/cron-decorator.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ test('Sends exceptions to Sentry on error in async cron job', async ({ baseURL }
7575
span_id: expect.stringMatching(/[a-f0-9]{16}/),
7676
});
7777

78+
expect(errorEvent.exception?.values?.[0]?.mechanism).toEqual({
79+
handled: false,
80+
type: 'auto.cron.nestjs.async',
81+
});
82+
7883
// kill cron so tests don't get stuck
7984
await fetch(`${baseURL}/kill-test-cron/test-async-cron-error`);
8085
});
@@ -92,6 +97,11 @@ test('Sends exceptions to Sentry on error in sync cron job', async ({ baseURL })
9297
span_id: expect.stringMatching(/[a-f0-9]{16}/),
9398
});
9499

100+
expect(errorEvent.exception?.values?.[0]?.mechanism).toEqual({
101+
handled: false,
102+
type: 'auto.cron.nestjs',
103+
});
104+
95105
// kill cron so tests don't get stuck
96106
await fetch(`${baseURL}/kill-test-cron/test-sync-cron-error`);
97107
});

‎dev-packages/e2e-tests/test-applications/nestjs-basic/tests/errors.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ test('Sends exception to Sentry', async ({ baseURL }) => {
1313

1414
expect(errorEvent.exception?.values).toHaveLength(1);
1515
expect(errorEvent.exception?.values?.[0]?.value).toBe('This is an exception with id 123');
16+
expect(errorEvent.exception?.values?.[0]?.mechanism).toEqual({
17+
handled: false,
18+
type: 'auto.http.nestjs.global_filter',
19+
});
1620

1721
expect(errorEvent.request).toEqual({
1822
method: 'GET',

‎dev-packages/e2e-tests/test-applications/nestjs-distributed-tracing/tests/events.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ test('Event emitter', async () => {
2121
type: 'Error',
2222
value: 'Test error from event handler',
2323
stacktrace: expect.any(Object),
24-
mechanism: expect.any(Object),
24+
mechanism: {
25+
handled: false,
26+
type: 'auto.event.nestjs',
27+
},
2528
},
2629
],
2730
});

‎dev-packages/e2e-tests/test-applications/nestjs-fastify/tests/cron-decorator.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ test('Sends exceptions to Sentry on error in cron job', async ({ baseURL }) => {
7171

7272
expect(errorEvent.exception?.values).toHaveLength(1);
7373
expect(errorEvent.exception?.values?.[0]?.value).toBe('Test error from cron job');
74+
expect(errorEvent.exception?.values?.[0]?.mechanism).toEqual({
75+
handled: false,
76+
type: 'auto.cron.nestjs.async',
77+
});
7478
expect(errorEvent.contexts?.trace).toEqual({
7579
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
7680
span_id: expect.stringMatching(/[a-f0-9]{16}/),

‎dev-packages/e2e-tests/test-applications/nestjs-fastify/tests/errors.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ test('Sends exception to Sentry', async ({ baseURL }) => {
1414
expect(errorEvent.exception?.values).toHaveLength(1);
1515
expect(errorEvent.exception?.values?.[0]?.value).toBe('This is an exception with id 123');
1616

17+
expect(errorEvent.exception?.values?.[0]?.mechanism).toEqual({
18+
handled: false,
19+
type: 'auto.http.nestjs.global_filter',
20+
});
21+
1722
expect(errorEvent.request).toEqual({
1823
method: 'GET',
1924
cookies: {},

‎dev-packages/e2e-tests/test-applications/nestjs-graphql/tests/errors.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ test('Sends exception to Sentry', async ({ baseURL }) => {
3232
expect(errorEvent.exception?.values).toHaveLength(1);
3333
expect(errorEvent.exception?.values?.[0]?.value).toBe('This is an exception!');
3434

35+
expect(errorEvent.exception?.values?.[0]?.mechanism).toEqual({
36+
handled: false,
37+
type: 'auto.graphql.nestjs.global_filter',
38+
});
39+
3540
expect(errorEvent.request).toEqual({
3641
method: 'POST',
3742
cookies: {},

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /