@@ -20,9 +20,7 @@ import type { RequestEvent as SrvxRequestEvent } from 'srvx/tracing';
2020 * Global object with the trace channels
2121 */
2222const globalWithTraceChannels = GLOBAL_OBJ as typeof GLOBAL_OBJ & {
23- __SENTRY_NITRO_H3_CHANNEL__ : ReturnType < typeof tracingChannel < H3TracingRequestEvent > > ;
24- __SENTRY_NITRO_SRVX_FETCH_CHANNEL__ : ReturnType < typeof tracingChannel < SrvxRequestEvent > > ;
25- __SENTRY_NITRO_SRVX_MIDDLEWARE_CHANNEL__ : ReturnType < typeof tracingChannel < SrvxRequestEvent > > ;
23+ __SENTRY_NITRO_HTTP_CHANNELS_INSTRUMENTED__ : boolean ;
2624} ;
2725
2826/**
@@ -31,8 +29,13 @@ const globalWithTraceChannels = GLOBAL_OBJ as typeof GLOBAL_OBJ & {
3129const NOOP = ( ) : void => { } ;
3230
3331export default definePlugin ( ( ) => {
32+ if ( globalWithTraceChannels . __SENTRY_NITRO_HTTP_CHANNELS_INSTRUMENTED__ ) {
33+ return ;
34+ }
35+
3436 setupH3TracingChannels ( ) ;
3537 setupSrvxTracingChannels ( ) ;
38+ globalWithTraceChannels . __SENTRY_NITRO_HTTP_CHANNELS_INSTRUMENTED__ = true ;
3639} ) ;
3740
3841function onTraceEnd ( data : { span ?: Span } ) : void {
@@ -46,11 +49,6 @@ function onTraceError(data: { span?: Span; error: unknown }): void {
4649}
4750
4851function setupH3TracingChannels ( ) : void {
49- // Already registered, don't register again
50- if ( globalWithTraceChannels . __SENTRY_NITRO_H3_CHANNEL__ ) {
51- return ;
52- }
53-
5452 const h3Channel = tracingChannel < H3TracingRequestEvent > ( 'h3.fetch' , data => {
5553 const parsedUrl = parseStringToURLObject ( data . event . url . href ) ;
5654 const [ spanName , urlAttributes ] = getHttpSpanDetailsFromUrlObject ( parsedUrl , 'server' , 'auto.http.nitro.h3' , {
@@ -76,18 +74,9 @@ function setupH3TracingChannels(): void {
7674 asyncEnd : onTraceEnd ,
7775 error : onTraceError ,
7876 } ) ;
79-
80- globalWithTraceChannels . __SENTRY_NITRO_H3_CHANNEL__ = h3Channel ;
8177}
8278
8379function setupSrvxTracingChannels ( ) : void {
84- if (
85- globalWithTraceChannels . __SENTRY_NITRO_SRVX_FETCH_CHANNEL__ ||
86- globalWithTraceChannels . __SENTRY_NITRO_SRVX_MIDDLEWARE_CHANNEL__
87- ) {
88- return ;
89- }
90-
9180 // Store the parent span for all middleware and fetch to share
9281 // This ensures they all appear as siblings in the trace
9382 let requestParentSpan : Span | null = null ;
@@ -173,7 +162,4 @@ function setupSrvxTracingChannels(): void {
173162 asyncEnd : onTraceEnd ,
174163 error : onTraceError ,
175164 } ) ;
176-
177- globalWithTraceChannels . __SENTRY_NITRO_SRVX_FETCH_CHANNEL__ = fetchChannel ;
178- globalWithTraceChannels . __SENTRY_NITRO_SRVX_MIDDLEWARE_CHANNEL__ = middlewareChannel ;
179165}
0 commit comments