@@ -98,6 +98,7 @@ export function callTracedServerSideDataFetcher<F extends (...args: any[]) => Pr
98
98
op : 'nextjs.data.server' ,
99
99
name : options . requestedRouteName ,
100
100
...traceparentData ,
101
+ status : 'ok' ,
101
102
metadata : {
102
103
source : 'route' ,
103
104
dynamicSamplingContext : traceparentData && ! dynamicSamplingContext ? { } : dynamicSamplingContext ,
@@ -116,6 +117,7 @@ export function callTracedServerSideDataFetcher<F extends (...args: any[]) => Pr
116
117
const dataFetcherSpan = requestTransaction . startChild ( {
117
118
op : 'nextjs.data.server' ,
118
119
description : `${ options . dataFetchingMethodName } (${ options . dataFetcherRouteName } )` ,
120
+ status : 'ok' ,
119
121
} ) ;
120
122
121
123
const currentScope = getCurrentHub ( ) . getScope ( ) ;
@@ -137,6 +139,17 @@ export function callTracedServerSideDataFetcher<F extends (...args: any[]) => Pr
137
139
138
140
try {
139
141
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 ;
140
153
} finally {
141
154
dataFetcherSpan . finish ( ) ;
142
155
}
@@ -178,14 +191,17 @@ export async function callDataFetcherTraced<F extends (...args: any[]) => Promis
178
191
const span = transaction . startChild ( {
179
192
op : 'nextjs.data.server' ,
180
193
description : `${ dataFetchingMethodName } (${ parameterizedRoute } )` ,
194
+ status : 'ok' ,
181
195
} ) ;
182
196
183
197
try {
184
198
return await origFunction ( ...origFunctionArgs ) ;
185
199
} 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 ( ) ;
189
205
190
206
// TODO Copy more robust error handling over from `withSentry`
191
207
captureException ( err ) ;
0 commit comments