@@ -9,8 +9,8 @@ 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 { generateSentryTraceHeader , generateTraceparentHeader , TRACEPARENT_REGEXP } from './tracing' ;
1414
1515/**
1616 * Extracts trace propagation data from the current span or from the client's scope (via transaction or propagation
@@ -58,7 +58,7 @@ export function getTraceData(
5858 } ;
5959
6060 if ( options . propagateTraceparent ) {
61- const traceparent = _sentryTraceToTraceParentHeader ( sentryTrace ) ;
61+ const traceparent = span ? spanToTraceparentHeader ( span ) : scopeToTraceparentHeader ( scope ) ;
6262 if ( traceparent ) {
6363 traceData . traceparent = traceparent ;
6464 }
@@ -75,22 +75,7 @@ function scopeToTraceHeader(scope: Scope): string {
7575 return generateSentryTraceHeader ( traceId , propagationSpanId , sampled ) ;
7676}
7777
78- /**
79- * Builds a W3C traceparent header from the given sentry-trace header.
80- *
81- * Why parse that header and not create traceparent from primitives?
82- * We want these two headers to always have the same ids. The easiest way to do this is to take
83- * one of them as the source of truth (sentry-trace) and derive the other from it.
84- *
85- * Most importantly, this guarantees parentSpanId consistency between sentry-trace and traceparent
86- * in tracing without performance (TwP) mode, where we always generate a random parentSpanId.
87- *
88- * Exported for testing
89- */
90- export function _sentryTraceToTraceParentHeader ( sentryTrace : string ) : string | undefined {
91- const { traceId, parentSpanId, parentSampled } = extractTraceparentData ( sentryTrace ) || { } ;
92- if ( ! traceId || ! parentSpanId ) {
93- return undefined ;
94- }
95- return `00-${ traceId } -${ parentSpanId } -${ parentSampled ? '01' : '00' } ` ;
78+ function scopeToTraceparentHeader ( scope : Scope ) : string {
79+ const { traceId, sampled, propagationSpanId } = scope . getPropagationContext ( ) ;
80+ return generateTraceparentHeader ( traceId , propagationSpanId , sampled ) ;
9681}
0 commit comments