@@ -9,8 +9,8 @@ import type { Span } from '../types-hoist/span';
9
9
import type { SerializedTraceData } from '../types-hoist/tracing' ;
10
10
import { dynamicSamplingContextToSentryBaggageHeader } from './baggage' ;
11
11
import { 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' ;
14
14
15
15
/**
16
16
* 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(
58
58
} ;
59
59
60
60
if ( options . propagateTraceparent ) {
61
- const traceparent = _sentryTraceToTraceParentHeader ( sentryTrace ) ;
61
+ const traceparent = span ? spanToTraceparentHeader ( span ) : scopeToTraceparentHeader ( scope ) ;
62
62
if ( traceparent ) {
63
63
traceData . traceparent = traceparent ;
64
64
}
@@ -75,22 +75,7 @@ function scopeToTraceHeader(scope: Scope): string {
75
75
return generateSentryTraceHeader ( traceId , propagationSpanId , sampled ) ;
76
76
}
77
77
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 ) ;
96
81
}
0 commit comments