@@ -3,10 +3,10 @@ import {
3
3
SPAN_STATUS_ERROR ,
4
4
SPAN_STATUS_OK ,
5
5
captureException ,
6
- getCurrentScope ,
7
6
handleCallbackErrors ,
8
7
startSpanManual ,
9
8
withIsolationScope ,
9
+ withScope ,
10
10
} from '@sentry/core' ;
11
11
import { propagationContextFromHeaders , winterCGHeadersToDict } from '@sentry/utils' ;
12
12
@@ -55,47 +55,50 @@ export function wrapServerComponentWithSentry<F extends (...args: any[]) => any>
55
55
const propagationContext = commonObjectToPropagationContext ( context . headers , incomingPropagationContext ) ;
56
56
57
57
return withIsolationScope ( isolationScope , ( ) => {
58
- isolationScope . setTransactionName ( `${ componentType } Server Component (${ componentRoute } )` ) ;
59
- getCurrentScope ( ) . setPropagationContext ( propagationContext ) ;
60
- return startSpanManual (
61
- {
62
- op : 'function.nextjs' ,
63
- name : `${ componentType } Server Component (${ componentRoute } )` ,
64
- forceTransaction : true ,
65
- attributes : {
66
- [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'component' ,
67
- [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.function.nextjs' ,
68
- } ,
69
- } ,
70
- span => {
71
- return handleCallbackErrors (
72
- ( ) => originalFunction . apply ( thisArg , args ) ,
73
- error => {
74
- if ( isNotFoundNavigationError ( error ) ) {
75
- // We don't want to report "not-found"s
76
- span . setStatus ( { code : SPAN_STATUS_ERROR , message : 'not_found' } ) ;
77
- } else if ( isRedirectNavigationError ( error ) ) {
78
- // We don't want to report redirects
79
- span . setStatus ( { code : SPAN_STATUS_OK } ) ;
80
- } else {
81
- span . setStatus ( { code : SPAN_STATUS_ERROR , message : 'internal_error' } ) ;
82
- captureException ( error , {
83
- mechanism : {
84
- handled : false ,
85
- } ,
86
- } ) ;
87
- }
88
- } ,
89
- ( ) => {
90
- span . end ( ) ;
58
+ return withScope ( scope => {
59
+ scope . setTransactionName ( `${ componentType } Server Component (${ componentRoute } )` ) ;
91
60
92
- // flushQueue should not throw
93
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
94
- flushQueue ( ) ;
61
+ scope . setPropagationContext ( propagationContext ) ;
62
+ return startSpanManual (
63
+ {
64
+ op : 'function.nextjs' ,
65
+ name : `${ componentType } Server Component (${ componentRoute } )` ,
66
+ forceTransaction : true ,
67
+ attributes : {
68
+ [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : 'component' ,
69
+ [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : 'auto.function.nextjs' ,
95
70
} ,
96
- ) ;
97
- } ,
98
- ) ;
71
+ } ,
72
+ span => {
73
+ return handleCallbackErrors (
74
+ ( ) => originalFunction . apply ( thisArg , args ) ,
75
+ error => {
76
+ if ( isNotFoundNavigationError ( error ) ) {
77
+ // We don't want to report "not-found"s
78
+ span . setStatus ( { code : SPAN_STATUS_ERROR , message : 'not_found' } ) ;
79
+ } else if ( isRedirectNavigationError ( error ) ) {
80
+ // We don't want to report redirects
81
+ span . setStatus ( { code : SPAN_STATUS_OK } ) ;
82
+ } else {
83
+ span . setStatus ( { code : SPAN_STATUS_ERROR , message : 'internal_error' } ) ;
84
+ captureException ( error , {
85
+ mechanism : {
86
+ handled : false ,
87
+ } ,
88
+ } ) ;
89
+ }
90
+ } ,
91
+ ( ) => {
92
+ span . end ( ) ;
93
+
94
+ // flushQueue should not throw
95
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
96
+ flushQueue ( ) ;
97
+ } ,
98
+ ) ;
99
+ } ,
100
+ ) ;
101
+ } ) ;
99
102
} ) ;
100
103
} ) ;
101
104
} ,
0 commit comments