@@ -9,8 +9,13 @@ import type { Span } from '../types-hoist/span';
99import type { SerializedTraceData } from '../types-hoist/tracing' ;
1010import { dynamicSamplingContextToSentryBaggageHeader } from './baggage' ;
1111import { debug } from './debug-logger' ;
12- import { getActiveSpan , spanToTraceHeader } from './spanUtils' ;
13- import { extractTraceparentData , generateSentryTraceHeader , TRACEPARENT_REGEXP } from './tracing' ;
12+ import { getActiveSpan , spanToTraceHeader , spanToTraceparentHeader } from './spanUtils' ;
13+ import {
14+ extractTraceparentData ,
15+ generateSentryTraceHeader ,
16+ generateTraceparentHeader ,
17+ TRACEPARENT_REGEXP ,
18+ } from './tracing' ;
1419
1520/**
1621 * Extracts trace propagation data from the current span or from the client's scope (via transaction or propagation
@@ -58,7 +63,7 @@ export function getTraceData(
5863 } ;
5964
6065 if ( options . propagateTraceparent ) {
61- traceData . traceparent = _sentryTraceToTraceParentHeader ( sentryTrace ) ;
66+ traceData . traceparent = span ? spanToTraceparentHeader ( span ) : scopeToTraceparentHeader ( scope ) ;
6267 }
6368
6469 return traceData ;
@@ -72,19 +77,7 @@ function scopeToTraceHeader(scope: Scope): string {
7277 return generateSentryTraceHeader ( traceId , propagationSpanId , sampled ) ;
7378}
7479
75- /**
76- * Builds a W3C traceparent header from the given sentry-trace header.
77- *
78- * Why parse that header and not create traceparent from primitives?
79- * We want these two headers to always have the same ids. The easiest way to do this is to take
80- * one of them as the source of truth (sentry-trace) and derive the other from it.
81- *
82- * Most importantly, this guarantees parentSpanId consistency between sentry-trace and traceparent
83- * in tracing without performance (TwP) mode, where we always generate a random parentSpanId.
84- *
85- * Exported for testing
86- */
87- export function _sentryTraceToTraceParentHeader ( sentryTrace : string ) : string {
88- const { traceId, parentSpanId, parentSampled } = extractTraceparentData ( sentryTrace ) || { } ;
89- return `00-${ traceId } -${ parentSpanId } -${ parentSampled ? '01' : '00' } ` ;
80+ function scopeToTraceparentHeader ( scope : Scope ) : string {
81+ const { traceId, sampled, propagationSpanId } = scope . getPropagationContext ( ) ;
82+ return generateTraceparentHeader ( traceId , propagationSpanId , sampled ) ;
9083}
0 commit comments