1
- import {
2
- SEMANTIC_ATTRIBUTE_SENTRY_OP ,
3
- SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ,
4
- SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ,
5
- SPAN_STATUS_ERROR ,
6
- Scope ,
7
- captureException ,
8
- getActiveSpan ,
9
- getCapturedScopesOnSpan ,
10
- getRootSpan ,
11
- handleCallbackErrors ,
12
- setCapturedScopesOnSpan ,
13
- setHttpStatus ,
14
- startSpan ,
15
- withIsolationScope ,
16
- withScope ,
17
- } from '@sentry/core' ;
18
- import { propagationContextFromHeaders , winterCGHeadersToDict } from '@sentry/utils' ;
19
- import { isNotFoundNavigationError , isRedirectNavigationError } from './nextNavigationErrorUtils' ;
1
+ import { Scope , getActiveSpan , getCapturedScopesOnSpan , getRootSpan , setCapturedScopesOnSpan } from '@sentry/core' ;
2
+
20
3
import type { RouteHandlerContext } from './types' ;
21
- import { flushSafelyWithTimeout } from './utils/responseEnd' ;
22
- import {
23
- commonObjectToIsolationScope ,
24
- commonObjectToPropagationContext ,
25
- escapeNextjsTracing ,
26
- } from './utils/tracingUtils' ;
27
- import { vercelWaitUntil } from './utils/vercelWaitUntil' ;
4
+
5
+ import { commonObjectToIsolationScope } from './utils/tracingUtils' ;
28
6
29
7
/**
30
8
* Wraps a Next.js App Router Route handler with Sentry error and performance instrumentation.
@@ -36,7 +14,7 @@ export function wrapRouteHandlerWithSentry<F extends (...args: any[]) => any>(
36
14
routeHandler : F ,
37
15
context : RouteHandlerContext ,
38
16
) : ( ...args : Parameters < F > ) => ReturnType < F > extends Promise < unknown > ? ReturnType < F > : Promise < ReturnType < F > > {
39
- const { method , parameterizedRoute , headers } = context ;
17
+ const { headers } = context ;
40
18
41
19
return new Proxy ( routeHandler , {
42
20
apply : ( originalFunction , thisArg , args ) => {
@@ -48,77 +26,12 @@ export function wrapRouteHandlerWithSentry<F extends (...args: any[]) => any>(
48
26
const { scope } = getCapturedScopesOnSpan ( rootSpan ) ;
49
27
setCapturedScopesOnSpan ( rootSpan , scope ?? new Scope ( ) , isolationScope ) ;
50
28
51
- // We mark the root span as an app route handler span so we can allow-list it in our span processor that would normally filter out all Next.js transactions/spans
29
+ // We mark the root span as an app route handler span so we can allow-list it in our span processor
30
+ // that would normally filter out all Next.js transactions/spans
52
31
rootSpan . setAttribute ( 'sentry.route_handler' , true ) ;
53
32
}
54
33
55
34
return originalFunction . apply ( thisArg , args ) ;
56
-
57
- // const completeHeadersDict: Record<string, string> = headers ? winterCGHeadersToDict(headers) : {};
58
-
59
- // isolationScope.setSDKProcessingMetadata({
60
- // request: {
61
- // headers: completeHeadersDict,
62
- // },
63
- // });
64
-
65
- // const incomingPropagationContext = propagationContextFromHeaders(
66
- // completeHeadersDict['sentry-trace'],
67
- // completeHeadersDict['baggage'],
68
- // );
69
-
70
- // const propagationContext = commonObjectToPropagationContext(headers, incomingPropagationContext);
71
-
72
- // return withIsolationScope(isolationScope, () => {
73
- // return withScope(async scope => {
74
- // scope.setTransactionName(`${method} ${parameterizedRoute}`);
75
- // scope.setPropagationContext(propagationContext);
76
- // try {
77
- // return startSpan(
78
- // {
79
- // name: `${method} ${parameterizedRoute}`,
80
- // attributes: {
81
- // [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'route',
82
- // [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.server',
83
- // [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.nextjs',
84
- // },
85
- // forceTransaction: true,
86
- // },
87
- // async span => {
88
- // const response: Response = await handleCallbackErrors(
89
- // () => originalFunction.apply(thisArg, args),
90
- // error => {
91
- // // Next.js throws errors when calling `redirect()`. We don't wanna report these.
92
- // if (isRedirectNavigationError(error)) {
93
- // // Don't do anything
94
- // } else if (isNotFoundNavigationError(error) && span) {
95
- // span.setStatus({ code: SPAN_STATUS_ERROR, message: 'not_found' });
96
- // } else {
97
- // captureException(error, {
98
- // mechanism: {
99
- // handled: false,
100
- // },
101
- // });
102
- // }
103
- // },
104
- // );
105
-
106
- // try {
107
- // if (span && response.status) {
108
- // setHttpStatus(span, response.status);
109
- // }
110
- // } catch {
111
- // // best effort - response may be undefined?
112
- // }
113
-
114
- // return response;
115
- // },
116
- // );
117
- // } finally {
118
- // vercelWaitUntil(flushSafelyWithTimeout());
119
- // }
120
- // });
121
- // });
122
35
} ,
123
36
} ) ;
124
37
}
0 commit comments