@@ -10,7 +10,6 @@ import {
1010 handleCallbackErrors ,
1111 setHttpStatus ,
1212 startSpan ,
13- withIsolationScope ,
1413} from '@sentry/core' ;
1514import type { Span } from '@sentry/types' ;
1615import { winterCGHeadersToDict } from '@sentry/utils' ;
@@ -22,10 +21,7 @@ import { withIsolationScopeOrReuseFromRootSpan } from './utils/withIsolationScop
2221
2322/** As our own HTTP integration is disabled (src/server/index.ts) the rootSpan comes from Next.js.
2423 * 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 > {
2925 const activeSpan = getActiveSpan ( ) ;
3026 const rootSpan = activeSpan && getRootSpan ( activeSpan ) ;
3127
@@ -35,7 +31,7 @@ function startOrUpdateSpan(
3531 rootSpan . setAttribute ( SEMANTIC_ATTRIBUTE_SENTRY_OP , 'http.server' ) ;
3632 rootSpan . setAttribute ( SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN , 'auto.function.nextjs' ) ;
3733
38- return handleResponseErrors ( rootSpan ) ;
34+ return cb ( rootSpan ) ;
3935 } else {
4036 return startSpan (
4137 {
@@ -48,7 +44,7 @@ function startOrUpdateSpan(
4844 } ,
4945 } ,
5046 ( span : Span ) => {
51- return handleResponseErrors ( span ) ;
47+ return cb ( span ) ;
5248 } ,
5349 ) ;
5450 }
@@ -68,7 +64,7 @@ export function wrapRouteHandlerWithSentry<F extends (...args: any[]) => any>(
6864
6965 return new Proxy ( routeHandler , {
7066 apply : ( originalFunction , thisArg , args ) => {
71- return withIsolationScope ( async isolationScope => {
67+ return withIsolationScopeOrReuseFromRootSpan ( async isolationScope => {
7268 isolationScope . setSDKProcessingMetadata ( {
7369 request : {
7470 headers : headers ? winterCGHeadersToDict ( headers ) : undefined ,
0 commit comments