@@ -9,8 +9,13 @@ 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 {
14
+ extractTraceparentData ,
15
+ generateSentryTraceHeader ,
16
+ generateTraceparentHeader ,
17
+ TRACEPARENT_REGEXP ,
18
+ } from './tracing' ;
14
19
15
20
/**
16
21
* 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(
58
63
} ;
59
64
60
65
if ( options . propagateTraceparent ) {
61
- traceData . traceparent = _sentryTraceToTraceParentHeader ( sentryTrace ) ;
66
+ traceData . traceparent = span ? spanToTraceparentHeader ( span ) : scopeToTraceparentHeader ( scope ) ;
62
67
}
63
68
64
69
return traceData ;
@@ -72,19 +77,7 @@ function scopeToTraceHeader(scope: Scope): string {
72
77
return generateSentryTraceHeader ( traceId , propagationSpanId , sampled ) ;
73
78
}
74
79
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 ) ;
90
83
}
0 commit comments