Skip to content

Commit 6e11be9

Browse files
authored
ref(nextjs): Set more specific event mechanisms (#17543)
exception mechanism now follows the trace origin naming scheme. Also added a couple of test assertions for tests expecting errors. closes #17258
1 parent d5f0ac3 commit 6e11be9

23 files changed

+89
-14
lines changed

dev-packages/e2e-tests/test-applications/nextjs-13/tests/client/click-error.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,18 @@ test('should send error for faulty click handlers', async ({ page }) => {
1313

1414
expect(errorEvent).toBeDefined();
1515

16-
const frames = errorEvent?.exception?.values?.[0]?.stacktrace?.frames;
16+
const exception = errorEvent?.exception?.values?.[0];
17+
18+
expect(exception?.mechanism).toEqual({
19+
type: 'auto.browser.browserapierrors.addEventListener',
20+
handled: false,
21+
data: {
22+
handler: expect.any(String), // the handler name varies in CI and locally
23+
target: 'EventTarget',
24+
},
25+
});
1726

27+
const frames = exception?.stacktrace?.frames;
1828
await test.step('error should have a non-url-encoded top frame in route with parameter', () => {
1929
if (process.env.TEST_ENV === 'development') {
2030
// In dev mode we want to check local source mapping

dev-packages/e2e-tests/test-applications/nextjs-13/tests/server/getServerSideProps.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test('Should report an error event for errors thrown in getServerSideProps', asy
2323
exception: {
2424
values: [
2525
{
26-
mechanism: { handled: false, type: 'generic' },
26+
mechanism: { handled: false, type: 'auto.function.nextjs.wrapped' },
2727
type: 'Error',
2828
value: 'getServerSideProps Error',
2929
stacktrace: {
@@ -110,7 +110,7 @@ test('Should report an error event for errors thrown in getServerSideProps in pa
110110
exception: {
111111
values: [
112112
{
113-
mechanism: { handled: false, type: 'generic' },
113+
mechanism: { handled: false, type: 'auto.function.nextjs.wrapped' },
114114
type: 'Error',
115115
value: 'custom page extension error',
116116
stacktrace: {

dev-packages/e2e-tests/test-applications/nextjs-13/tests/server/pages-router-api-endpoints.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ test('Should report an error event for errors thrown in pages router api routes'
3030
function: 'withSentry',
3131
},
3232
handled: false,
33-
type: 'instrument',
33+
type: 'auto.http.nextjs.api_handler',
3434
},
3535
stacktrace: { frames: expect.arrayContaining([]) },
3636
type: 'Error',

dev-packages/e2e-tests/test-applications/nextjs-13/tests/server/server-component-error.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test('Should capture an error thrown in a server component', async ({ page }) =>
2020
exception: {
2121
values: [
2222
{
23-
mechanism: { handled: false, type: 'generic' },
23+
mechanism: { handled: false, type: 'auto.function.nextjs.server_component' },
2424
type: 'Error',
2525
value: 'RSC error',
2626
},

dev-packages/e2e-tests/test-applications/nextjs-15/tests/nested-rsc-error.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ test('Should capture errors from nested server components when `Sentry.captureRe
4141
router_path: '/nested-rsc-error/[param]',
4242
request_path: '/nested-rsc-error/123',
4343
});
44+
45+
expect(errorEvent.exception?.values?.[0]?.mechanism).toEqual({
46+
handled: false,
47+
type: 'auto.function.nextjs.on_request_error',
48+
});
4449
});

dev-packages/e2e-tests/test-applications/nextjs-15/tests/streaming-rsc-error.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,9 @@ test('Should capture errors for crashing streaming promises in server components
4141
router_path: '/streaming-rsc-error/[param]',
4242
request_path: '/streaming-rsc-error/123',
4343
});
44+
45+
expect(errorEvent.exception?.values?.[0]?.mechanism).toEqual({
46+
handled: false,
47+
type: 'auto.function.nextjs.on_request_error',
48+
});
4449
});

dev-packages/e2e-tests/test-applications/nextjs-app-dir/tests/client-errors.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,15 @@ test('Sends a client-side exception to Sentry', async ({ page }) => {
3535
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
3636
span_id: expect.stringMatching(/[a-f0-9]{16}/),
3737
});
38+
39+
expect(errorEvent.exception?.values?.[0]?.mechanism).toEqual({
40+
handled: false,
41+
type: nextjsMajor >= 15 ? 'auto.browser.global_handlers.onerror' : 'auto.browser.browserapierrors.addEventListener',
42+
...(nextjsMajor < 15 && {
43+
data: {
44+
handler: expect.any(String), // the handler name varies in CI and locally
45+
target: 'EventTarget',
46+
},
47+
}),
48+
});
3849
});

dev-packages/e2e-tests/test-applications/nextjs-app-dir/tests/edge.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ test('Should record exceptions for faulty edge server components', async ({ page
1919
expect(errorEvent.tags?.['my-global-scope-isolated-tag']).not.toBeDefined();
2020

2121
expect(errorEvent.transaction).toBe(`Page Server Component (/edge-server-components/error)`);
22+
23+
expect(errorEvent.exception?.values?.[0]?.mechanism).toEqual({
24+
handled: false,
25+
type: 'auto.function.nextjs.server_component',
26+
});
2227
});
2328

2429
test('Should record transaction for edge server components', async ({ page }) => {

dev-packages/e2e-tests/test-applications/nextjs-orpc/tests/orpc-error.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ test('should capture orpc error', async ({ page }) => {
1919
}),
2020
],
2121
});
22+
23+
// orpc errors are captured manually by the orpc middleware (user-land)
24+
expect(orpcError.exception?.values?.[0]?.mechanism).toEqual({
25+
handled: true,
26+
type: 'generic',
27+
});
2228
});

dev-packages/e2e-tests/test-applications/nextjs-pages-dir/tests/pages-ssr-errors.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@ test('Will capture error for SSR rendering error with a connected trace (Functio
4343
// TODO(lforst): Reuse SSR request span isolation scope to fix the following two assertions
4444
// expect(ssrTransaction.tags?.['my-isolated-tag']).toBe(true);
4545
// expect(ssrTransaction.tags?.['my-global-scope-isolated-tag']).not.toBeDefined();
46+
47+
expect(errorEvent.exception?.values?.[0]?.mechanism).toEqual({
48+
handled: false,
49+
type: 'auto.function.nextjs.page_function',
50+
});
4651
});

0 commit comments

Comments
 (0)