@@ -3,36 +3,28 @@ import type { Client, Scope, SerializedTraceData, Span } from '@sentry/core';
33import {
44 dynamicSamplingContextToSentryBaggageHeader ,
55 generateSentryTraceHeader ,
6+ generateTraceparentHeader ,
67 getCapturedScopesOnSpan ,
7- scopeToTraceparentHeader ,
8- spanToTraceparentHeader ,
98} from '@sentry/core' ;
109import { getInjectionData } from '../propagator' ;
11- import { getContextFromScope , getScopesFromContext } from './contextData' ;
10+ import { getContextFromScope } from './contextData' ;
1211
1312/**
1413 * Otel-specific implementation of `getTraceData`.
1514 * @see `@sentry/core` version of `getTraceData` for more information
1615 */
17- export function getTraceData ( options : { span ?: Span ; scope ?: Scope ; client ?: Client ; propagateTraceparent ?: boolean } = { } ) : SerializedTraceData {
18- const { client, propagateTraceparent } = options ;
19- let { span, scope } = options ;
20-
16+ export function getTraceData ( {
17+ span,
18+ scope,
19+ client,
20+ propagateTraceparent,
21+ } : { span ?: Span ; scope ?: Scope ; client ?: Client ; propagateTraceparent ?: boolean } = { } ) : SerializedTraceData {
2122 let ctx = ( scope && getContextFromScope ( scope ) ) ?? api . context . active ( ) ;
2223
2324 if ( span ) {
2425 const { scope } = getCapturedScopesOnSpan ( span ) ;
2526 // fall back to current context if for whatever reason we can't find the one of the span
2627 ctx = ( scope && getContextFromScope ( scope ) ) || api . trace . setSpan ( api . context . active ( ) , span ) ;
27- } else {
28- span = api . trace . getSpan ( ctx ) ;
29- }
30-
31- if ( ! scope ) {
32- const scopes = getScopesFromContext ( ctx ) ;
33- if ( scopes ) {
34- scope = scopes . scope ;
35- }
3628 }
3729
3830 const { traceId, spanId, sampled, dynamicSamplingContext } = getInjectionData ( ctx , { scope, client } ) ;
@@ -43,11 +35,7 @@ export function getTraceData(options: { span?: Span; scope?: Scope; client?: Cli
4335 } ;
4436
4537 if ( propagateTraceparent ) {
46- if ( span ) {
47- traceData . traceparent = spanToTraceparentHeader ( span ) ;
48- } else if ( scope ) {
49- traceData . traceparent = scopeToTraceparentHeader ( scope ) ;
50- }
38+ traceData . traceparent = generateTraceparentHeader ( traceId , spanId , sampled ) ;
5139 }
5240
5341 return traceData ;
0 commit comments