diff --git a/dev-packages/e2e-tests/test-applications/nestjs-with-submodules/src/instrument.ts b/dev-packages/e2e-tests/test-applications/nestjs-with-submodules/src/instrument.ts index aa4c76f13ee5..4f16ebb36d11 100644 --- a/dev-packages/e2e-tests/test-applications/nestjs-with-submodules/src/instrument.ts +++ b/dev-packages/e2e-tests/test-applications/nestjs-with-submodules/src/instrument.ts @@ -1,7 +1,6 @@ import * as Sentry from '@sentry/nestjs'; Sentry.init({ - traceLifecycle: 'static', environment: 'qa', // dynamic sampling bias to keep transactions dsn: process.env.E2E_TEST_DSN, tunnel: `http://localhost:3031/`, // proxy server diff --git a/dev-packages/e2e-tests/test-applications/nestjs-with-submodules/tests/errors.test.ts b/dev-packages/e2e-tests/test-applications/nestjs-with-submodules/tests/errors.test.ts index eb3a3d809417..41ab1126d706 100644 --- a/dev-packages/e2e-tests/test-applications/nestjs-with-submodules/tests/errors.test.ts +++ b/dev-packages/e2e-tests/test-applications/nestjs-with-submodules/tests/errors.test.ts @@ -1,8 +1,10 @@ import { expect, test } from '@playwright/test'; -import { waitForError, waitForTransaction } from '@sentry-internal/test-utils'; +import { collectStreamedSpansUntilSegment, waitForError } from '@sentry-internal/test-utils'; + +const APP_NAME = 'nestjs-with-submodules'; test('Sends unexpected exception to Sentry if thrown in module with global filter', async ({ baseURL }) => { - const errorEventPromise = waitForError('nestjs-with-submodules', event => { + const errorEventPromise = waitForError(APP_NAME, event => { return !event.type && event.exception?.values?.[0]?.value === 'This is an uncaught exception!'; }); @@ -36,7 +38,7 @@ test('Sends unexpected exception to Sentry if thrown in module with global filte }); test('Sends unexpected exception to Sentry if thrown in module with local filter', async ({ baseURL }) => { - const errorEventPromise = waitForError('nestjs-with-submodules', event => { + const errorEventPromise = waitForError(APP_NAME, event => { return !event.type && event.exception?.values?.[0]?.value === 'This is an uncaught exception!'; }); @@ -72,7 +74,7 @@ test('Sends unexpected exception to Sentry if thrown in module with local filter test('Sends unexpected exception to Sentry if thrown in module that was registered before Sentry', async ({ baseURL, }) => { - const errorEventPromise = waitForError('nestjs-with-submodules', event => { + const errorEventPromise = waitForError(APP_NAME, event => { return !event.type && event.exception?.values?.[0]?.value === 'This is an uncaught exception!'; }); @@ -110,7 +112,7 @@ test('Does not send exception to Sentry if user-defined global exception filter }) => { let errorEventOccurred = false; - waitForError('nestjs-with-submodules', event => { + waitForError(APP_NAME, event => { if (!event.type && event.exception?.values?.[0]?.value === 'Something went wrong in the example module!') { errorEventOccurred = true; } @@ -118,16 +120,16 @@ test('Does not send exception to Sentry if user-defined global exception filter return event?.transaction === 'GET /example-module/expected-exception'; }); - const transactionEventPromise = waitForTransaction('nestjs-with-submodules', transactionEvent => { - return transactionEvent?.transaction === 'GET /example-module/expected-exception'; - }); + // Waiting for each request's segment span is how this spec knows the request finished and + // any error it would have produced had its chance to be sent. + const spansPromise = collectStreamedSpansUntilSegment(APP_NAME, 'GET /example-module/expected-exception'); const response = await fetch(`${baseURL}/example-module/expected-exception`); expect(response.status).toBe(400); - await transactionEventPromise; + await spansPromise; - (await fetch(`${baseURL}/flush`)).text(); + await fetch(`${baseURL}/flush`); expect(errorEventOccurred).toBe(false); }); @@ -137,7 +139,7 @@ test('Does not send exception to Sentry if user-defined local exception filter a }) => { let errorEventOccurred = false; - waitForError('nestjs-with-submodules', event => { + waitForError(APP_NAME, event => { if ( !event.type && event.exception?.values?.[0]?.value === 'Something went wrong in the example module with local filter!' @@ -148,16 +150,17 @@ test('Does not send exception to Sentry if user-defined local exception filter a return event?.transaction === 'GET /example-module-local-filter/expected-exception'; }); - const transactionEventPromise = waitForTransaction('nestjs-with-submodules', transactionEvent => { - return transactionEvent?.transaction === 'GET /example-module-local-filter/expected-exception'; - }); + const spansPromise = collectStreamedSpansUntilSegment( + APP_NAME, + 'GET /example-module-local-filter/expected-exception', + ); const response = await fetch(`${baseURL}/example-module-local-filter/expected-exception`); expect(response.status).toBe(400); - await transactionEventPromise; + await spansPromise; - (await fetch(`${baseURL}/flush`)).text(); + await fetch(`${baseURL}/flush`); expect(errorEventOccurred).toBe(false); }); @@ -167,7 +170,7 @@ test('Does not send expected exception to Sentry if exception is thrown in modul }) => { let errorEventOccurred = false; - waitForError('nestjs-with-submodules', event => { + waitForError(APP_NAME, event => { if (!event.type && event.exception?.values?.[0].value === 'Something went wrong in the example module!') { errorEventOccurred = true; } @@ -175,16 +178,17 @@ test('Does not send expected exception to Sentry if exception is thrown in modul return event?.transaction === 'GET /example-module-registered-first/expected-exception'; }); - const transactionEventPromise = waitForTransaction('nestjs-with-submodules', transactionEvent => { - return transactionEvent?.transaction === 'GET /example-module-registered-first/expected-exception'; - }); + const spansPromise = collectStreamedSpansUntilSegment( + APP_NAME, + 'GET /example-module-registered-first/expected-exception', + ); const response = await fetch(`${baseURL}/example-module-registered-first/expected-exception`); expect(response.status).toBe(400); - await transactionEventPromise; + await spansPromise; - (await fetch(`${baseURL}/flush`)).text(); + await fetch(`${baseURL}/flush`); expect(errorEventOccurred).toBe(false); }); @@ -194,7 +198,7 @@ test('Global specific exception filter registered in main module is applied and }) => { let errorEventOccurred = false; - waitForError('nestjs-with-submodules', event => { + waitForError(APP_NAME, event => { if (!event.type && event.exception?.values?.[0]?.value === 'Example exception was handled by specific filter!') { errorEventOccurred = true; } @@ -202,9 +206,7 @@ test('Global specific exception filter registered in main module is applied and return event?.transaction === 'GET /example-exception-specific-filter'; }); - const transactionEventPromise = waitForTransaction('nestjs-with-submodules', transactionEvent => { - return transactionEvent?.transaction === 'GET /example-exception-specific-filter'; - }); + const spansPromise = collectStreamedSpansUntilSegment(APP_NAME, 'GET /example-exception-specific-filter'); const response = await fetch(`${baseURL}/example-exception-specific-filter`); const responseBody = await response.json(); @@ -217,9 +219,9 @@ test('Global specific exception filter registered in main module is applied and message: 'Example exception was handled by specific filter!', }); - await transactionEventPromise; + await spansPromise; - (await fetch(`${baseURL}/flush`)).text(); + await fetch(`${baseURL}/flush`); expect(errorEventOccurred).toBe(false); }); @@ -229,7 +231,7 @@ test('Local specific exception filter registered in main module is applied and e }) => { let errorEventOccurred = false; - waitForError('nestjs-with-submodules', event => { + waitForError(APP_NAME, event => { if (!event.type && event.exception?.values?.[0]?.value === 'Example exception was handled by local filter!') { errorEventOccurred = true; } @@ -237,9 +239,7 @@ test('Local specific exception filter registered in main module is applied and e return event?.transaction === 'GET /example-exception-local-filter'; }); - const transactionEventPromise = waitForTransaction('nestjs-with-submodules', transactionEvent => { - return transactionEvent?.transaction === 'GET /example-exception-local-filter'; - }); + const spansPromise = collectStreamedSpansUntilSegment(APP_NAME, 'GET /example-exception-local-filter'); const response = await fetch(`${baseURL}/example-exception-local-filter`); const responseBody = await response.json(); @@ -252,9 +252,9 @@ test('Local specific exception filter registered in main module is applied and e message: 'Example exception was handled by local filter!', }); - await transactionEventPromise; + await spansPromise; - (await fetch(`${baseURL}/flush`)).text(); + await fetch(`${baseURL}/flush`); expect(errorEventOccurred).toBe(false); }); diff --git a/dev-packages/e2e-tests/test-applications/nestjs-with-submodules/tests/spans.test.ts b/dev-packages/e2e-tests/test-applications/nestjs-with-submodules/tests/spans.test.ts new file mode 100644 index 000000000000..c3aee02d14d5 --- /dev/null +++ b/dev-packages/e2e-tests/test-applications/nestjs-with-submodules/tests/spans.test.ts @@ -0,0 +1,207 @@ +import { expect, test } from '@playwright/test'; +import type { SerializedStreamedSpan } from '@sentry-internal/test-utils'; +import { collectStreamedSpansUntilSegment } from '@sentry-internal/test-utils'; + +const APP_NAME = 'nestjs-with-submodules'; + +const SPAN_ID = /^[a-f0-9]{16}$/; +const TRACE_ID = /^[a-f0-9]{32}$/; + +function findSpan(spans: SerializedStreamedSpan[], name: string): SerializedStreamedSpan | undefined { + return spans.find(span => span.name === name); +} + +/** + * The attributes span streaming puts on every span of a trace. Spelling them out is what lets the + * child span assertions below use `toEqual`, so an unexpected attribute fails the test. + */ +function commonAttributes(segmentSpan: SerializedStreamedSpan): Record { + return { + 'sentry.trace_lifecycle': { type: 'string', value: 'stream' }, + 'sentry.segment.name': { type: 'string', value: segmentSpan.name }, + 'sentry.segment.id': { type: 'string', value: segmentSpan.span_id }, + 'sentry.sdk.name': { type: 'string', value: 'sentry.javascript.nestjs' }, + 'sentry.sdk.version': { type: 'string', value: expect.any(String) }, + 'sentry.environment': { type: 'string', value: 'qa' }, + // CI builds the apps with a release, local runs have none. It comes from the client + // options, so whatever the segment span got, every other span of the trace got too. + ...(segmentSpan.attributes['sentry.release'] + ? { 'sentry.release': { type: 'string', value: expect.any(String) } } + : {}), + }; +} + +/** A manually started span, which carries nothing beyond the common attributes. */ +function manualSpan(segmentSpan: SerializedStreamedSpan, name: string, parentSpanId: string): Record { + return { + name, + span_id: expect.stringMatching(SPAN_ID), + trace_id: segmentSpan.trace_id, + parent_span_id: parentSpanId, + start_timestamp: expect.any(Number), + end_timestamp: expect.any(Number), + is_segment: false, + status: 'ok', + attributes: { + ...commonAttributes(segmentSpan), + 'sentry.origin': { type: 'string', value: 'manual' }, + }, + }; +} + +/** An exception filter span, which the specs below assert on by name. */ +function exceptionFilterSpan(segmentSpan: SerializedStreamedSpan, name: string): Record { + return { + name, + span_id: expect.stringMatching(SPAN_ID), + trace_id: segmentSpan.trace_id, + parent_span_id: expect.stringMatching(SPAN_ID), + start_timestamp: expect.any(Number), + end_timestamp: expect.any(Number), + is_segment: false, + status: 'ok', + attributes: { + ...commonAttributes(segmentSpan), + 'sentry.op': { type: 'string', value: 'middleware' }, + 'sentry.origin': { type: 'string', value: 'auto.middleware.nestjs.exception_filter' }, + }, + }; +} + +test('Sends streamed spans for an API route from module', async ({ baseURL }) => { + const spansPromise = collectStreamedSpansUntilSegment(APP_NAME, 'GET /example-module/transaction'); + + await fetch(`${baseURL}/example-module/transaction`); + + const spans = await spansPromise; + const segmentSpan = spans.find(span => span.is_segment)!; + + // The segment span additionally carries the scope's contexts (os, device, runtime, culture), the + // SDK's integration list and the user's IP, all of which vary by machine, so only the + // request-specific attributes are pinned here. The child spans below are matched exhaustively. + expect(segmentSpan).toEqual({ + name: 'GET /example-module/transaction', + span_id: expect.stringMatching(SPAN_ID), + trace_id: expect.stringMatching(TRACE_ID), + start_timestamp: expect.any(Number), + end_timestamp: expect.any(Number), + is_segment: true, + status: 'ok', + attributes: expect.objectContaining({ + ...commonAttributes(segmentSpan), + 'sentry.origin': { type: 'string', value: 'auto.http.http_server' }, + 'sentry.op': { type: 'string', value: 'http.server' }, + 'sentry.segment.name.source': { type: 'string', value: 'route' }, + 'sentry.sample_rate': { type: 'integer', value: 1 }, + 'sentry.kind': { type: 'string', value: 'server' }, + 'http.request.method': { type: 'string', value: 'GET' }, + 'http.route': { type: 'string', value: '/example-module/transaction' }, + 'http.response.status_code': { type: 'integer', value: 200 }, + 'http.response.status_text': { type: 'string', value: 'OK' }, + 'url.full': { type: 'string', value: 'http://localhost:3030/example-module/transaction' }, + 'url.path': { type: 'string', value: '/example-module/transaction' }, + 'url.scheme': { type: 'string', value: 'http' }, + 'server.address': { type: 'string', value: 'localhost' }, + 'server.port': { type: 'integer', value: 3030 }, + 'user_agent.original': { type: 'string', value: 'node' }, + }), + }); + + expect(findSpan(spans, '/example-module/transaction')).toEqual({ + name: '/example-module/transaction', + span_id: expect.stringMatching(SPAN_ID), + trace_id: segmentSpan.trace_id, + parent_span_id: segmentSpan.span_id, + start_timestamp: expect.any(Number), + end_timestamp: expect.any(Number), + is_segment: false, + status: 'ok', + attributes: { + ...commonAttributes(segmentSpan), + 'sentry.op': { type: 'string', value: 'handler' }, + 'sentry.origin': { type: 'string', value: 'auto.http.express' }, + 'express.name': { type: 'string', value: '/example-module/transaction' }, + 'express.type': { type: 'string', value: 'request_handler' }, + 'http.route': { type: 'string', value: '/example-module/transaction' }, + }, + }); + + // The Nest handler span carries the callback name as an attribute rather than in its name, which + // stays low cardinality under span streaming. + const nestHandlerSpan = findSpan(spans, 'Request handler'); + expect(nestHandlerSpan).toEqual({ + name: 'Request handler', + span_id: expect.stringMatching(SPAN_ID), + trace_id: segmentSpan.trace_id, + parent_span_id: expect.stringMatching(SPAN_ID), + start_timestamp: expect.any(Number), + end_timestamp: expect.any(Number), + is_segment: false, + status: 'ok', + attributes: { + ...commonAttributes(segmentSpan), + 'sentry.op': { type: 'string', value: 'handler' }, + 'sentry.origin': { type: 'string', value: 'auto.http.nestjs' }, + component: { type: 'string', value: '@nestjs/core' }, + 'nestjs.type': { type: 'string', value: 'handler' }, + 'nestjs.callback': { type: 'string', value: 'testTransaction' }, + 'nestjs.version': { type: 'string', value: expect.any(String) }, + }, + }); + + const testSpan = findSpan(spans, 'test-span'); + expect(testSpan).toEqual(manualSpan(segmentSpan, 'test-span', nestHandlerSpan!.span_id)); + expect(findSpan(spans, 'child-span')).toEqual(manualSpan(segmentSpan, 'child-span', testSpan!.span_id)); +}); + +test('API route trace includes exception filter span for global filter in module registered after Sentry', async ({ + baseURL, +}) => { + const spansPromise = collectStreamedSpansUntilSegment(APP_NAME, 'GET /example-module/expected-exception'); + + const response = await fetch(`${baseURL}/example-module/expected-exception`); + expect(response.status).toBe(400); + + const spans = await spansPromise; + + const segmentSpan = spans.find(span => span.is_segment)!; + expect(findSpan(spans, 'ExampleExceptionFilter')).toEqual(exceptionFilterSpan(segmentSpan, 'ExampleExceptionFilter')); +}); + +test('API route trace includes exception filter span for local filter in module registered after Sentry', async ({ + baseURL, +}) => { + const spansPromise = collectStreamedSpansUntilSegment( + APP_NAME, + 'GET /example-module-local-filter/expected-exception', + ); + + const response = await fetch(`${baseURL}/example-module-local-filter/expected-exception`); + expect(response.status).toBe(400); + + const spans = await spansPromise; + + const segmentSpan = spans.find(span => span.is_segment)!; + expect(findSpan(spans, 'LocalExampleExceptionFilter')).toEqual( + exceptionFilterSpan(segmentSpan, 'LocalExampleExceptionFilter'), + ); +}); + +test('API route trace includes exception filter span for global filter in module registered before Sentry', async ({ + baseURL, +}) => { + const spansPromise = collectStreamedSpansUntilSegment( + APP_NAME, + 'GET /example-module-registered-first/expected-exception', + ); + + const response = await fetch(`${baseURL}/example-module-registered-first/expected-exception`); + expect(response.status).toBe(400); + + const spans = await spansPromise; + + const segmentSpan = spans.find(span => span.is_segment)!; + expect(findSpan(spans, 'ExampleExceptionFilterRegisteredFirst')).toEqual( + exceptionFilterSpan(segmentSpan, 'ExampleExceptionFilterRegisteredFirst'), + ); +}); diff --git a/dev-packages/e2e-tests/test-applications/nestjs-with-submodules/tests/transactions.test.ts b/dev-packages/e2e-tests/test-applications/nestjs-with-submodules/tests/transactions.test.ts deleted file mode 100644 index c5829a9425bc..000000000000 --- a/dev-packages/e2e-tests/test-applications/nestjs-with-submodules/tests/transactions.test.ts +++ /dev/null @@ -1,248 +0,0 @@ -import { expect, test } from '@playwright/test'; -import { waitForTransaction } from '@sentry-internal/test-utils'; - -test('Sends an API route transaction from module', async ({ baseURL }) => { - const pageloadTransactionEventPromise = waitForTransaction('nestjs-with-submodules', transactionEvent => { - return ( - transactionEvent?.contexts?.trace?.op === 'http.server' && - transactionEvent?.transaction === 'GET /example-module/transaction' - ); - }); - - await fetch(`${baseURL}/example-module/transaction`); - - const transactionEvent = await pageloadTransactionEventPromise; - - expect(transactionEvent.contexts?.trace).toEqual({ - data: { - 'sentry.segment.name.source': 'route', - 'sentry.origin': 'auto.http.http_server', - 'sentry.op': 'http.server', - 'sentry.sample_rate': 1, - 'sentry.kind': 'server', - 'http.response.status_code': 200, - 'url.full': 'http://localhost:3030/example-module/transaction', - 'url.path': '/example-module/transaction', - 'server.address': 'localhost', - 'http.request.method': 'GET', - 'url.scheme': 'http', - 'user_agent.original': 'node', - 'client.address': '::1', - 'client.port': expect.any(Number), - 'network.transport': 'tcp', - 'network.local.address': expect.any(String), - 'network.local.port': expect.any(Number), - 'network.peer.address': expect.any(String), - 'network.peer.port': expect.any(Number), - 'network.protocol.name': 'http', - 'network.protocol.version': '1.1', - 'server.port': 3030, - 'http.response.status_text': 'OK', - 'http.route': '/example-module/transaction', - 'http.request.header.accept': '*/*', - 'http.request.header.accept_encoding': 'gzip, deflate', - 'http.request.header.accept_language': '*', - 'http.request.header.connection': 'keep-alive', - 'http.request.header.host': expect.any(String), - 'http.request.header.sec_fetch_mode': 'cors', - 'http.request.header.user_agent': 'node', - }, - op: 'http.server', - span_id: expect.stringMatching(/[a-f0-9]{16}/), - status: 'ok', - trace_id: expect.stringMatching(/[a-f0-9]{32}/), - origin: 'auto.http.http_server', - }); - - expect(transactionEvent).toEqual( - expect.objectContaining({ - spans: expect.arrayContaining([ - { - data: { - 'express.name': '/example-module/transaction', - 'express.type': 'request_handler', - 'http.route': '/example-module/transaction', - 'sentry.origin': 'auto.http.express', - 'sentry.op': 'handler', - }, - op: 'handler', - description: '/example-module/transaction', - parent_span_id: expect.stringMatching(/[a-f0-9]{16}/), - span_id: expect.stringMatching(/[a-f0-9]{16}/), - start_timestamp: expect.any(Number), - status: 'ok', - timestamp: expect.any(Number), - trace_id: expect.stringMatching(/[a-f0-9]{32}/), - origin: 'auto.http.express', - }, - { - data: { - 'sentry.origin': 'manual', - }, - description: 'test-span', - parent_span_id: expect.stringMatching(/[a-f0-9]{16}/), - span_id: expect.stringMatching(/[a-f0-9]{16}/), - start_timestamp: expect.any(Number), - status: 'ok', - timestamp: expect.any(Number), - trace_id: expect.stringMatching(/[a-f0-9]{32}/), - origin: 'manual', - }, - { - data: { - 'sentry.origin': 'manual', - }, - description: 'child-span', - parent_span_id: expect.stringMatching(/[a-f0-9]{16}/), - span_id: expect.stringMatching(/[a-f0-9]{16}/), - start_timestamp: expect.any(Number), - status: 'ok', - timestamp: expect.any(Number), - trace_id: expect.stringMatching(/[a-f0-9]{32}/), - origin: 'manual', - }, - { - span_id: expect.stringMatching(/[a-f0-9]{16}/), - trace_id: expect.stringMatching(/[a-f0-9]{32}/), - data: { - 'sentry.origin': 'auto.http.nestjs', - 'sentry.op': 'handler', - component: '@nestjs/core', - 'nestjs.version': expect.any(String), - 'nestjs.type': 'handler', - 'nestjs.callback': 'testTransaction', - }, - description: 'testTransaction', - parent_span_id: expect.stringMatching(/[a-f0-9]{16}/), - start_timestamp: expect.any(Number), - timestamp: expect.any(Number), - status: 'ok', - origin: 'auto.http.nestjs', - op: 'handler', - }, - ]), - transaction: 'GET /example-module/transaction', - type: 'transaction', - transaction_info: { - source: 'route', - }, - }), - ); -}); - -test('API route transaction includes exception filter span for global filter in module registered after Sentry', async ({ - baseURL, -}) => { - const transactionEventPromise = waitForTransaction('nestjs-with-submodules', transactionEvent => { - return ( - transactionEvent?.contexts?.trace?.op === 'http.server' && - transactionEvent?.transaction === 'GET /example-module/expected-exception' && - transactionEvent?.request?.url?.includes('/example-module/expected-exception') - ); - }); - - const response = await fetch(`${baseURL}/example-module/expected-exception`); - expect(response.status).toBe(400); - - const transactionEvent = await transactionEventPromise; - - expect(transactionEvent).toEqual( - expect.objectContaining({ - spans: expect.arrayContaining([ - { - span_id: expect.stringMatching(/[a-f0-9]{16}/), - trace_id: expect.stringMatching(/[a-f0-9]{32}/), - data: { - 'sentry.op': 'middleware', - 'sentry.origin': 'auto.middleware.nestjs.exception_filter', - }, - description: 'ExampleExceptionFilter', - parent_span_id: expect.stringMatching(/[a-f0-9]{16}/), - start_timestamp: expect.any(Number), - timestamp: expect.any(Number), - status: 'ok', - op: 'middleware', - origin: 'auto.middleware.nestjs.exception_filter', - }, - ]), - }), - ); -}); - -test('API route transaction includes exception filter span for local filter in module registered after Sentry', async ({ - baseURL, -}) => { - const transactionEventPromise = waitForTransaction('nestjs-with-submodules', transactionEvent => { - return ( - transactionEvent?.contexts?.trace?.op === 'http.server' && - transactionEvent?.transaction === 'GET /example-module-local-filter/expected-exception' && - transactionEvent?.request?.url?.includes('/example-module-local-filter/expected-exception') - ); - }); - - const response = await fetch(`${baseURL}/example-module-local-filter/expected-exception`); - expect(response.status).toBe(400); - - const transactionEvent = await transactionEventPromise; - - expect(transactionEvent).toEqual( - expect.objectContaining({ - spans: expect.arrayContaining([ - { - span_id: expect.stringMatching(/[a-f0-9]{16}/), - trace_id: expect.stringMatching(/[a-f0-9]{32}/), - data: { - 'sentry.op': 'middleware', - 'sentry.origin': 'auto.middleware.nestjs.exception_filter', - }, - description: 'LocalExampleExceptionFilter', - parent_span_id: expect.stringMatching(/[a-f0-9]{16}/), - start_timestamp: expect.any(Number), - timestamp: expect.any(Number), - status: 'ok', - op: 'middleware', - origin: 'auto.middleware.nestjs.exception_filter', - }, - ]), - }), - ); -}); - -test('API route transaction includes exception filter span for global filter in module registered before Sentry', async ({ - baseURL, -}) => { - const transactionEventPromise = waitForTransaction('nestjs-with-submodules', transactionEvent => { - return ( - transactionEvent?.contexts?.trace?.op === 'http.server' && - transactionEvent?.transaction === 'GET /example-module-registered-first/expected-exception' && - transactionEvent?.request?.url?.includes('/example-module-registered-first/expected-exception') - ); - }); - - const response = await fetch(`${baseURL}/example-module-registered-first/expected-exception`); - expect(response.status).toBe(400); - - const transactionEvent = await transactionEventPromise; - - expect(transactionEvent).toEqual( - expect.objectContaining({ - spans: expect.arrayContaining([ - { - span_id: expect.stringMatching(/[a-f0-9]{16}/), - trace_id: expect.stringMatching(/[a-f0-9]{32}/), - data: { - 'sentry.op': 'middleware', - 'sentry.origin': 'auto.middleware.nestjs.exception_filter', - }, - description: 'ExampleExceptionFilterRegisteredFirst', - parent_span_id: expect.stringMatching(/[a-f0-9]{16}/), - start_timestamp: expect.any(Number), - timestamp: expect.any(Number), - status: 'ok', - op: 'middleware', - origin: 'auto.middleware.nestjs.exception_filter', - }, - ]), - }), - ); -});