|
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'; |
11 | 2 | import { flushSafelyWithTimeout, waitUntil } from '../common/utils/responseEnd'; |
12 | 3 | import type { EdgeRouteHandler } from '../edge/types'; |
13 | 4 |
|
@@ -49,52 +40,20 @@ export function wrapMiddlewareWithSentry<H extends EdgeRouteHandler>( |
49 | 40 | } |
50 | 41 | } |
51 | 42 |
|
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 | + }, |
62 | 51 | }); |
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 | + ); |
98 | 57 | }, |
99 | 58 | }); |
100 | 59 | } |
0 commit comments