@@ -114,6 +114,7 @@ export class SentryNodeFetchInstrumentation extends InstrumentationBase<SentryNo
114114 * This method is called when a request is created.
115115 * You can still mutate the request here before it is sent.
116116 */
117+ // eslint-disable-next-line complexity
117118 private _onRequestCreated ( { request } : { request : UndiciRequest } ) : void {
118119 const config = this . getConfig ( ) ;
119120 const enabled = config . enabled !== false ;
@@ -137,16 +138,16 @@ export class SentryNodeFetchInstrumentation extends InstrumentationBase<SentryNo
137138 // Note: We do not use `propagation.inject()` here, because our propagator relies on an active span
138139 // Which we do not have in this case
139140 // The propagator _may_ overwrite this, but this should be fine as it is the same data
140- const tracePropagationTargets = getClient ( ) ?. getOptions ( ) . tracePropagationTargets ;
141+ const { tracePropagationTargets, propagateTraceparent } = getClient ( ) ?. getOptions ( ) || { } ;
141142 const addedHeaders = shouldPropagateTraceForUrl ( url , tracePropagationTargets , this . _propagationDecisionMap )
142- ? getTraceData ( )
143+ ? getTraceData ( { propagateTraceparent } )
143144 : undefined ;
144145
145146 if ( ! addedHeaders ) {
146147 return ;
147148 }
148149
149- const { 'sentry-trace' : sentryTrace , baggage } = addedHeaders ;
150+ const { 'sentry-trace' : sentryTrace , baggage, traceparent } = addedHeaders ;
150151
151152 // We do not want to overwrite existing headers here
152153 // If the core UndiciInstrumentation is registered, it will already have set the headers
@@ -159,6 +160,10 @@ export class SentryNodeFetchInstrumentation extends InstrumentationBase<SentryNo
159160 requestHeaders . push ( SENTRY_TRACE_HEADER , sentryTrace ) ;
160161 }
161162
163+ if ( traceparent && ! requestHeaders . includes ( 'traceparent' ) ) {
164+ requestHeaders . push ( 'traceparent' , traceparent ) ;
165+ }
166+
162167 // For baggage, we make sure to merge this into a possibly existing header
163168 const existingBaggagePos = requestHeaders . findIndex ( header => header === SENTRY_BAGGAGE_HEADER ) ;
164169 if ( baggage && existingBaggagePos === - 1 ) {
@@ -177,6 +182,10 @@ export class SentryNodeFetchInstrumentation extends InstrumentationBase<SentryNo
177182 request . headers += `${ SENTRY_TRACE_HEADER } : ${ sentryTrace } \r\n` ;
178183 }
179184
185+ if ( traceparent && ! requestHeaders . includes ( 'traceparent:' ) ) {
186+ request . headers += `traceparent: ${ traceparent } \r\n` ;
187+ }
188+
180189 const existingBaggage = request . headers . match ( BAGGAGE_HEADER_REGEX ) ?. [ 1 ] ;
181190 if ( baggage && ! existingBaggage ) {
182191 request . headers += `${ SENTRY_BAGGAGE_HEADER } : ${ baggage } \r\n` ;
0 commit comments