@@ -98,6 +98,7 @@ export function callTracedServerSideDataFetcher<F extends (...args: any[]) => Pr
9898 op : 'nextjs.data.server' ,
9999 name : options . requestedRouteName ,
100100 ...traceparentData ,
101+ status : 'ok' ,
101102 metadata : {
102103 source : 'route' ,
103104 dynamicSamplingContext : traceparentData && ! dynamicSamplingContext ? { } : dynamicSamplingContext ,
@@ -116,6 +117,7 @@ export function callTracedServerSideDataFetcher<F extends (...args: any[]) => Pr
116117 const dataFetcherSpan = requestTransaction . startChild ( {
117118 op : 'nextjs.data.server' ,
118119 description : `${ options . dataFetchingMethodName } (${ options . dataFetcherRouteName } )` ,
120+ status : 'ok' ,
119121 } ) ;
120122
121123 const currentScope = getCurrentHub ( ) . getScope ( ) ;
@@ -137,6 +139,17 @@ export function callTracedServerSideDataFetcher<F extends (...args: any[]) => Pr
137139
138140 try {
139141 return await origFunction ( ...origFunctionArguments ) ;
142+ } catch ( e ) {
143+ // Since we finish the span before the error can bubble up and trigger the handlers in `registerErrorInstrumentation`
144+ // that set the transaction status, we need to manually set the status of the span & transaction
145+ dataFetcherSpan . setStatus ( 'internal_error' ) ;
146+
147+ const transaction = dataFetcherSpan . transaction ;
148+ if ( transaction ) {
149+ transaction . setStatus ( 'internal_error' ) ;
150+ }
151+
152+ throw e ;
140153 } finally {
141154 dataFetcherSpan . finish ( ) ;
142155 }
@@ -178,14 +191,17 @@ export async function callDataFetcherTraced<F extends (...args: any[]) => Promis
178191 const span = transaction . startChild ( {
179192 op : 'nextjs.data.server' ,
180193 description : `${ dataFetchingMethodName } (${ parameterizedRoute } )` ,
194+ status : 'ok' ,
181195 } ) ;
182196
183197 try {
184198 return await origFunction ( ...origFunctionArgs ) ;
185199 } catch ( err ) {
186- if ( span ) {
187- span . finish ( ) ;
188- }
200+ // Since we finish the span before the error can bubble up and trigger the handlers in `registerErrorInstrumentation`
201+ // that set the transaction status, we need to manually set the status of the span & transaction
202+ transaction . setStatus ( 'internal_error' ) ;
203+ span . setStatus ( 'internal_error' ) ;
204+ span . finish ( ) ;
189205
190206 // TODO Copy more robust error handling over from `withSentry`
191207 captureException ( err ) ;
0 commit comments