1- import { spanToJSON } from '@sentry/core' ;
1+ import { getCurrentScope , spanToJSON } from '@sentry/core' ;
22import {
33 SEMANTIC_ATTRIBUTE_SENTRY_OP ,
44 SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ,
@@ -13,7 +13,7 @@ import {
1313 startSpan ,
1414 withIsolationScope ,
1515} from '@sentry/core' ;
16- import { getSpanScopes } from '@sentry/opentelemetry' ;
16+ import { getSpanScopes , setSpanScopes } from '@sentry/opentelemetry' ;
1717import type { Span } from '@sentry/types' ;
1818import { winterCGHeadersToDict } from '@sentry/utils' ;
1919import { isNotFoundNavigationError , isRedirectNavigationError } from './nextNavigationErrorUtils' ;
@@ -84,8 +84,15 @@ export function wrapRouteHandlerWithSentry<F extends (...args: any[]) => any>(
8484 return await startOrUpdateSpan ( `${ method } ${ parameterizedRoute } ` , async ( rootSpan : Span ) => {
8585 // Ensure root span has the correct isolation scope - even if it was triggered by next
8686 const scopes = getSpanScopes ( rootSpan ) ;
87+ rootSpan . setAttribute ( 'has_span_scopes' , ! ! scopes ) ;
88+ console . log ( 'getting scopes' , scopes ) ;
8789 if ( scopes ) {
8890 scopes . isolationScope = isolationScope ;
91+ } else {
92+ setSpanScopes ( rootSpan , {
93+ scope : getCurrentScope ( ) ,
94+ isolationScope,
95+ } ) ;
8996 }
9097
9198 const response : Response = await handleCallbackErrors (
0 commit comments