Skip to content

Commit 3431fe5

Browse files
committed
feat(nextjs): Remove tracing from middelware wrappers
1 parent 8596086 commit 3431fe5

File tree

1 file changed

+12
-30
lines changed

1 file changed

+12
-30
lines changed

packages/nextjs/src/common/wrapMiddlewareWithSentry.ts

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
import type { TransactionSource } from '@sentry/core';
21
import {
32
captureException,
43
getActiveSpan,
54
getCurrentScope,
65
getRootSpan,
76
handleCallbackErrors,
8-
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
9-
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
107
setCapturedScopesOnSpan,
11-
startSpan,
128
winterCGRequestToRequestData,
139
withIsolationScope,
1410
} from '@sentry/core';
@@ -31,6 +27,7 @@ export function wrapMiddlewareWithSentry<H extends EdgeRouteHandler>(
3127
? (globalThis as Record<string, unknown>)._sentryRewritesTunnelPath
3228
: undefined;
3329

30+
// TODO: This can never work with Turbopack, need to remove it for consistency between builds.
3431
if (tunnelRoute && typeof tunnelRoute === 'string') {
3532
const req: unknown = args[0];
3633
// Check if the current request matches the tunnel route
@@ -51,23 +48,21 @@ export function wrapMiddlewareWithSentry<H extends EdgeRouteHandler>(
5148
}
5249
}
5350
}
51+
5452
// TODO: We still should add central isolation scope creation for when our build-time instrumentation does not work anymore with turbopack.
5553
return withIsolationScope(isolationScope => {
5654
const req: unknown = args[0];
5755
const currentScope = getCurrentScope();
5856

5957
let spanName: string;
60-
let spanSource: TransactionSource;
6158

6259
if (req instanceof Request) {
6360
isolationScope.setSDKProcessingMetadata({
6461
normalizedRequest: winterCGRequestToRequestData(req),
6562
});
6663
spanName = `middleware ${req.method}`;
67-
spanSource = 'url';
6864
} else {
6965
spanName = 'middleware';
70-
spanSource = 'component';
7166
}
7267

7368
currentScope.setTransactionName(spanName);
@@ -78,38 +73,25 @@ export function wrapMiddlewareWithSentry<H extends EdgeRouteHandler>(
7873
// If there is an active span, it likely means that the automatic Next.js OTEL instrumentation worked and we can
7974
// rely on that for parameterization.
8075
spanName = 'middleware';
81-
spanSource = 'component';
8276

8377
const rootSpan = getRootSpan(activeSpan);
8478
if (rootSpan) {
8579
setCapturedScopesOnSpan(rootSpan, currentScope, isolationScope);
8680
}
8781
}
8882

89-
return startSpan(
90-
{
91-
name: spanName,
92-
op: 'http.server.middleware',
93-
attributes: {
94-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: spanSource,
95-
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs.wrap_middleware',
96-
},
83+
return handleCallbackErrors(
84+
() => wrappingTarget.apply(thisArg, args),
85+
error => {
86+
captureException(error, {
87+
mechanism: {
88+
type: 'auto.function.nextjs.wrap_middleware',
89+
handled: false,
90+
},
91+
});
9792
},
9893
() => {
99-
return handleCallbackErrors(
100-
() => wrappingTarget.apply(thisArg, args),
101-
error => {
102-
captureException(error, {
103-
mechanism: {
104-
type: 'auto.function.nextjs.wrap_middleware',
105-
handled: false,
106-
},
107-
});
108-
},
109-
() => {
110-
waitUntil(flushSafelyWithTimeout());
111-
},
112-
);
94+
waitUntil(flushSafelyWithTimeout());
11395
},
11496
);
11597
});

0 commit comments

Comments
 (0)