From b897e2850614e87276948d40d2f748bf2be65ddd Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Thu, 31 Jul 2025 11:27:55 +0200 Subject: [PATCH 1/4] ref(node): Add mechanism to errors captured from `connect` error middleware --- packages/node/src/integrations/tracing/connect.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/node/src/integrations/tracing/connect.ts b/packages/node/src/integrations/tracing/connect.ts index c2ab3716bd33..ed19c90fdd98 100644 --- a/packages/node/src/integrations/tracing/connect.ts +++ b/packages/node/src/integrations/tracing/connect.ts @@ -48,7 +48,12 @@ export const connectIntegration = defineIntegration(_connectIntegration); // eslint-disable-next-line @typescript-eslint/no-explicit-any function connectErrorMiddleware(err: any, req: any, res: any, next: any): void { - captureException(err); + captureException(err, { + mechanism: { + handled: false, + type: 'connect', + }, + }); next(err); } From 9ffc41c006f2a0443d60d1824fbb3db24b3e83eb Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Thu, 31 Jul 2025 11:28:57 +0200 Subject: [PATCH 2/4] ref(node): Add `mechanism` to errors captured from koa error handler --- packages/node/src/integrations/tracing/koa.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/node/src/integrations/tracing/koa.ts b/packages/node/src/integrations/tracing/koa.ts index 487f471a9a12..4dc2f1403c87 100644 --- a/packages/node/src/integrations/tracing/koa.ts +++ b/packages/node/src/integrations/tracing/koa.ts @@ -134,7 +134,12 @@ export const setupKoaErrorHandler = (app: { use: (arg0: (ctx: any, next: any) => try { await next(); } catch (error) { - captureException(error); + captureException(error, { + mechanism: { + handled: false, + type: 'koa', + }, + }); throw error; } }); From e16866c32efd7989418efae4f94eaf65f11a0577 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Tue, 9 Sep 2025 16:48:22 +0200 Subject: [PATCH 3/4] ref(node): Add mechanism to errors captured via connect and koa integrations --- .../test-applications/node-connect/tests/errors.test.ts | 5 +++++ .../test-applications/node-koa/tests/errors.test.ts | 5 +++++ packages/node/src/integrations/tracing/connect.ts | 2 +- packages/node/src/integrations/tracing/koa.ts | 2 +- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/dev-packages/e2e-tests/test-applications/node-connect/tests/errors.test.ts b/dev-packages/e2e-tests/test-applications/node-connect/tests/errors.test.ts index 2aa569915eb4..1ad27b923715 100644 --- a/dev-packages/e2e-tests/test-applications/node-connect/tests/errors.test.ts +++ b/dev-packages/e2e-tests/test-applications/node-connect/tests/errors.test.ts @@ -26,4 +26,9 @@ test('Sends correct error event', async ({ baseURL }) => { trace_id: expect.stringMatching(/[a-f0-9]{32}/), span_id: expect.stringMatching(/[a-f0-9]{16}/), }); + + expect(errorEvent.mechanism).toEqual({ + type: 'auto.middleware.connect', + handled: false, + }); }); diff --git a/dev-packages/e2e-tests/test-applications/node-koa/tests/errors.test.ts b/dev-packages/e2e-tests/test-applications/node-koa/tests/errors.test.ts index cadf29fbda90..333a69908919 100644 --- a/dev-packages/e2e-tests/test-applications/node-koa/tests/errors.test.ts +++ b/dev-packages/e2e-tests/test-applications/node-koa/tests/errors.test.ts @@ -27,4 +27,9 @@ test('Sends correct error event', async ({ baseURL }) => { span_id: expect.stringMatching(/[a-f0-9]{16}/), parent_span_id: expect.stringMatching(/[a-f0-9]{16}/), }); + + expect(errorEvent.mechanism).toEqual({ + type: 'auto.middleware.koa', + handled: false, + }); }); diff --git a/packages/node/src/integrations/tracing/connect.ts b/packages/node/src/integrations/tracing/connect.ts index ed19c90fdd98..3fd7d10b28fb 100644 --- a/packages/node/src/integrations/tracing/connect.ts +++ b/packages/node/src/integrations/tracing/connect.ts @@ -51,7 +51,7 @@ function connectErrorMiddleware(err: any, req: any, res: any, next: any): void { captureException(err, { mechanism: { handled: false, - type: 'connect', + type: 'auto.middleware.connect', }, }); next(err); diff --git a/packages/node/src/integrations/tracing/koa.ts b/packages/node/src/integrations/tracing/koa.ts index 4dc2f1403c87..7125479e91e0 100644 --- a/packages/node/src/integrations/tracing/koa.ts +++ b/packages/node/src/integrations/tracing/koa.ts @@ -137,7 +137,7 @@ export const setupKoaErrorHandler = (app: { use: (arg0: (ctx: any, next: any) => captureException(error, { mechanism: { handled: false, - type: 'koa', + type: 'auto.middleware.koa', }, }); throw error; From a16ae6bca380fd00ae0313e3d260394225953bf7 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Tue, 9 Sep 2025 16:50:11 +0200 Subject: [PATCH 4/4] fix tests --- .../node-connect/tests/errors.test.ts | 13 +++++++------ .../test-applications/node-koa/tests/errors.test.ts | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/dev-packages/e2e-tests/test-applications/node-connect/tests/errors.test.ts b/dev-packages/e2e-tests/test-applications/node-connect/tests/errors.test.ts index 1ad27b923715..c8d7b3123482 100644 --- a/dev-packages/e2e-tests/test-applications/node-connect/tests/errors.test.ts +++ b/dev-packages/e2e-tests/test-applications/node-connect/tests/errors.test.ts @@ -11,7 +11,13 @@ test('Sends correct error event', async ({ baseURL }) => { const errorEvent = await errorEventPromise; expect(errorEvent.exception?.values).toHaveLength(1); - expect(errorEvent.exception?.values?.[0]?.value).toBe('This is an exception'); + const exception = errorEvent.exception?.values?.[0]; + expect(exception?.value).toBe('This is an exception'); + + expect(exception?.mechanism).toEqual({ + type: 'auto.middleware.connect', + handled: false, + }); expect(errorEvent.request).toEqual({ method: 'GET', @@ -26,9 +32,4 @@ test('Sends correct error event', async ({ baseURL }) => { trace_id: expect.stringMatching(/[a-f0-9]{32}/), span_id: expect.stringMatching(/[a-f0-9]{16}/), }); - - expect(errorEvent.mechanism).toEqual({ - type: 'auto.middleware.connect', - handled: false, - }); }); diff --git a/dev-packages/e2e-tests/test-applications/node-koa/tests/errors.test.ts b/dev-packages/e2e-tests/test-applications/node-koa/tests/errors.test.ts index 333a69908919..dd0dfa4a084d 100644 --- a/dev-packages/e2e-tests/test-applications/node-koa/tests/errors.test.ts +++ b/dev-packages/e2e-tests/test-applications/node-koa/tests/errors.test.ts @@ -11,7 +11,13 @@ test('Sends correct error event', async ({ baseURL }) => { const errorEvent = await errorEventPromise; expect(errorEvent.exception?.values).toHaveLength(1); - expect(errorEvent.exception?.values?.[0]?.value).toBe('This is an exception with id 123'); + const exception = errorEvent.exception?.values?.[0]; + + expect(exception?.value).toBe('This is an exception with id 123'); + expect(exception?.mechanism).toEqual({ + type: 'auto.middleware.koa', + handled: false, + }); expect(errorEvent.request).toEqual({ method: 'GET', @@ -27,9 +33,4 @@ test('Sends correct error event', async ({ baseURL }) => { span_id: expect.stringMatching(/[a-f0-9]{16}/), parent_span_id: expect.stringMatching(/[a-f0-9]{16}/), }); - - expect(errorEvent.mechanism).toEqual({ - type: 'auto.middleware.koa', - handled: false, - }); });