File tree Expand file tree Collapse file tree
packages/nitro/src/runtime/plugins Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77 httpHeadersToSpanAttributes ,
88 parseStringToURLObject ,
99 SEMANTIC_ATTRIBUTE_SENTRY_OP ,
10+ setHttpStatus ,
1011 type Span ,
1112 SPAN_STATUS_ERROR ,
1213 startSpanManual ,
@@ -43,8 +44,24 @@ export default definePlugin(nitroApp => {
4344 globalWithTraceChannels . __SENTRY_NITRO_HTTP_CHANNELS_INSTRUMENTED__ = true ;
4445} ) ;
4546
46- function onTraceEnd ( data : { span ?: Span } ) : void {
47- data . span ?. end ( ) ;
47+ /**
48+ * Extracts the HTTP status code from a tracing channel result.
49+ * The result is the return value of the traced handler, which is a Response for srvx
50+ * and may or may not be a Response for h3.
51+ */
52+ function getResponseStatusCode ( result : unknown ) : number | undefined {
53+ if ( result && typeof result === 'object' && 'status' in result && typeof result . status === 'number' ) {
54+ return result . status ;
55+ }
56+ return undefined ;
57+ }
58+
59+ function onTraceEnd ( data : { span ?: Span ; result ?: unknown } ) : void {
60+ const statusCode = getResponseStatusCode ( data . result ) ;
61+ if ( data . span && statusCode !== undefined ) {
62+ setHttpStatus ( data . span , statusCode ) ;
63+ data . span . end ( ) ;
64+ }
4865}
4966
5067function onTraceError ( data : { span ?: Span ; error : unknown } ) : void {
@@ -120,7 +137,6 @@ function setupSrvxTracingChannels(): void {
120137 asyncStart : ( ) => { } ,
121138 end : ( ) => { } ,
122139 asyncEnd : data => {
123- // data.span?.setAttribute('http.response.status_code', data.result.);
124140 onTraceEnd ( data ) ;
125141
126142 // Reset parent span reference after the fetch handler completes
You can’t perform that action at this time.
0 commit comments