@@ -10,7 +10,6 @@ import {
10
10
handleCallbackErrors ,
11
11
setHttpStatus ,
12
12
startSpan ,
13
- withIsolationScope ,
14
13
} from '@sentry/core' ;
15
14
import type { Span } from '@sentry/types' ;
16
15
import { winterCGHeadersToDict } from '@sentry/utils' ;
@@ -22,10 +21,7 @@ import { withIsolationScopeOrReuseFromRootSpan } from './utils/withIsolationScop
22
21
23
22
/** As our own HTTP integration is disabled (src/server/index.ts) the rootSpan comes from Next.js.
24
23
* In case there is not root span, we start a new span. */
25
- function startOrUpdateSpan (
26
- spanName : string ,
27
- handleResponseErrors : ( rootSpan : Span ) => Promise < Response > ,
28
- ) : Promise < Response > {
24
+ function startOrUpdateSpan ( spanName : string , cb : ( rootSpan : Span ) => Promise < Response > ) : Promise < Response > {
29
25
const activeSpan = getActiveSpan ( ) ;
30
26
const rootSpan = activeSpan && getRootSpan ( activeSpan ) ;
31
27
@@ -35,7 +31,7 @@ function startOrUpdateSpan(
35
31
rootSpan . setAttribute ( SEMANTIC_ATTRIBUTE_SENTRY_OP , 'http.server' ) ;
36
32
rootSpan . setAttribute ( SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN , 'auto.function.nextjs' ) ;
37
33
38
- return handleResponseErrors ( rootSpan ) ;
34
+ return cb ( rootSpan ) ;
39
35
} else {
40
36
return startSpan (
41
37
{
@@ -48,7 +44,7 @@ function startOrUpdateSpan(
48
44
} ,
49
45
} ,
50
46
( span : Span ) => {
51
- return handleResponseErrors ( span ) ;
47
+ return cb ( span ) ;
52
48
} ,
53
49
) ;
54
50
}
@@ -68,7 +64,7 @@ export function wrapRouteHandlerWithSentry<F extends (...args: any[]) => any>(
68
64
69
65
return new Proxy ( routeHandler , {
70
66
apply : ( originalFunction , thisArg , args ) => {
71
- return withIsolationScope ( async isolationScope => {
67
+ return withIsolationScopeOrReuseFromRootSpan ( async isolationScope => {
72
68
isolationScope . setSDKProcessingMetadata ( {
73
69
request : {
74
70
headers : headers ? winterCGHeadersToDict ( headers ) : undefined ,
0 commit comments