@@ -13,6 +13,7 @@ import {
1313 startSpan ,
1414 withIsolationScope ,
1515} from '@sentry/core' ;
16+ import { getSpanScopes } from '@sentry/opentelemetry' ;
1617import type { Span } from '@sentry/types' ;
1718import { winterCGHeadersToDict } from '@sentry/utils' ;
1819import { isNotFoundNavigationError , isRedirectNavigationError } from './nextNavigationErrorUtils' ;
@@ -69,7 +70,6 @@ export function wrapRouteHandlerWithSentry<F extends (...args: any[]) => any>(
6970 return new Proxy ( routeHandler , {
7071 apply : ( originalFunction , thisArg , args ) => {
7172 return withIsolationScope ( async isolationScope => {
72- console . log ( 'SETTING ISOLATION SCOPE' ) ;
7373 isolationScope . setSDKProcessingMetadata ( {
7474 request : {
7575 headers : headers ? winterCGHeadersToDict ( headers ) : undefined ,
@@ -78,6 +78,12 @@ export function wrapRouteHandlerWithSentry<F extends (...args: any[]) => any>(
7878
7979 try {
8080 return await startOrUpdateSpan ( `${ method } ${ parameterizedRoute } ` , async ( rootSpan : Span ) => {
81+ // Ensure root span has the correct isolation scope - even if it was triggered by next
82+ const scopes = getSpanScopes ( rootSpan ) ;
83+ if ( scopes ) {
84+ scopes . isolationScope = isolationScope ;
85+ }
86+
8187 const response : Response = await handleCallbackErrors (
8288 ( ) => originalFunction . apply ( thisArg , args ) ,
8389 error => {
0 commit comments