Skip to content

feat(nestjs): Stop creating spans for TracingInterceptor #16501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,36 +112,6 @@ test('Sends an API route transaction', async ({ baseURL }) => {
op: 'request_context.nestjs',
origin: 'auto.http.otel.nestjs',
},
{
span_id: expect.stringMatching(/[a-f0-9]{16}/),
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
data: {
'sentry.origin': 'auto.middleware.nestjs',
'sentry.op': 'middleware.nestjs',
},
description: 'SentryTracingInterceptor',
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
start_timestamp: expect.any(Number),
timestamp: expect.any(Number),
status: 'ok',
op: 'middleware.nestjs',
origin: 'auto.middleware.nestjs',
},
{
span_id: expect.stringMatching(/[a-f0-9]{16}/),
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
data: {
'sentry.origin': 'auto.middleware.nestjs',
'sentry.op': 'middleware.nestjs',
},
description: 'SentryTracingInterceptor',
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
start_timestamp: expect.any(Number),
timestamp: expect.any(Number),
status: 'ok',
op: 'middleware.nestjs',
origin: 'auto.middleware.nestjs',
},
{
span_id: expect.stringMatching(/[a-f0-9]{16}/),
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
Expand Down Expand Up @@ -183,29 +153,19 @@ test('Sends an API route transaction', async ({ baseURL }) => {
status: 'ok',
origin: 'manual',
},
{
span_id: expect.stringMatching(/[a-f0-9]{16}/),
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
data: {
'sentry.origin': 'auto.middleware.nestjs',
'sentry.op': 'middleware.nestjs',
},
description: 'Interceptors - After Route',
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
start_timestamp: expect.any(Number),
timestamp: expect.any(Number),
status: 'ok',
op: 'middleware.nestjs',
origin: 'auto.middleware.nestjs',
},
]),
start_timestamp: expect.any(Number),
timestamp: expect.any(Number),
transaction: 'GET /test-transaction',
type: 'transaction',
transaction_info: {
source: 'route',
},
type: 'transaction',
}),
);

const spanDescriptions = transactionEvent.spans.map(span => span.description);
expect(spanDescriptions).not.toContain('SentryTracingInterceptor');
});

test('API route transaction includes nest middleware span. Spans created in and after middleware are nested correctly', async ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,12 @@ export class SentryNestInstrumentation extends InstrumentationBase {
const parentSpan = getActiveSpan();
let afterSpan: Span | undefined;

// Check that we can reasonably assume that the target is an interceptor.
if (!context || !next || typeof next.handle !== 'function') {
if (
!context ||
!next ||
typeof next.handle !== 'function' || // Check that we can reasonably assume that the target is an interceptor.
target.name === 'SentryTracingInterceptor' // We don't want to trace this internal interceptor
) {
return originalIntercept.apply(thisArgIntercept, argsIntercept);
}

Expand Down
Loading