Skip to content

Commit f687f59

Browse files
committed
feat: remove all span ops from middleware wrapper
1 parent 3431fe5 commit f687f59

File tree

1 file changed

+14
-55
lines changed

1 file changed

+14
-55
lines changed
Lines changed: 14 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
import {
2-
captureException,
3-
getActiveSpan,
4-
getCurrentScope,
5-
getRootSpan,
6-
handleCallbackErrors,
7-
setCapturedScopesOnSpan,
8-
winterCGRequestToRequestData,
9-
withIsolationScope,
10-
} from '@sentry/core';
1+
import { captureException, handleCallbackErrors } from '@sentry/core';
112
import { flushSafelyWithTimeout, waitUntil } from '../common/utils/responseEnd';
123
import type { EdgeRouteHandler } from '../edge/types';
134

@@ -49,52 +40,20 @@ export function wrapMiddlewareWithSentry<H extends EdgeRouteHandler>(
4940
}
5041
}
5142

52-
// TODO: We still should add central isolation scope creation for when our build-time instrumentation does not work anymore with turbopack.
53-
return withIsolationScope(isolationScope => {
54-
const req: unknown = args[0];
55-
const currentScope = getCurrentScope();
56-
57-
let spanName: string;
58-
59-
if (req instanceof Request) {
60-
isolationScope.setSDKProcessingMetadata({
61-
normalizedRequest: winterCGRequestToRequestData(req),
43+
return handleCallbackErrors(
44+
() => wrappingTarget.apply(thisArg, args),
45+
error => {
46+
captureException(error, {
47+
mechanism: {
48+
type: 'auto.function.nextjs.wrap_middleware',
49+
handled: false,
50+
},
6251
});
63-
spanName = `middleware ${req.method}`;
64-
} else {
65-
spanName = 'middleware';
66-
}
67-
68-
currentScope.setTransactionName(spanName);
69-
70-
const activeSpan = getActiveSpan();
71-
72-
if (activeSpan) {
73-
// If there is an active span, it likely means that the automatic Next.js OTEL instrumentation worked and we can
74-
// rely on that for parameterization.
75-
spanName = 'middleware';
76-
77-
const rootSpan = getRootSpan(activeSpan);
78-
if (rootSpan) {
79-
setCapturedScopesOnSpan(rootSpan, currentScope, isolationScope);
80-
}
81-
}
82-
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-
});
92-
},
93-
() => {
94-
waitUntil(flushSafelyWithTimeout());
95-
},
96-
);
97-
});
52+
},
53+
() => {
54+
waitUntil(flushSafelyWithTimeout());
55+
},
56+
);
9857
},
9958
});
10059
}

0 commit comments

Comments
 (0)