Skip to content

Commit b1f4ccf

Browse files
committed
fix(opentelemetry): Always use active span in getInjectionData
1 parent e1783a6 commit b1f4ccf

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/opentelemetry/src/propagator.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ export class SentryPropagator extends W3CBaggagePropagator {
9393
const activeSpan = trace.getSpan(context);
9494
const url = activeSpan && getCurrentURL(activeSpan);
9595

96+
console.log('1', { activeSpan, url });
97+
9698
const tracePropagationTargets = getClient()?.getOptions()?.tracePropagationTargets;
9799
if (
98100
typeof url === 'string' &&
@@ -104,6 +106,7 @@ export class SentryPropagator extends W3CBaggagePropagator {
104106
'[Tracing] Not injecting trace data for url because it does not match tracePropagationTargets:',
105107
url,
106108
);
109+
console.log('2', { tracePropagationTargets });
107110
return;
108111
}
109112

@@ -112,6 +115,7 @@ export class SentryPropagator extends W3CBaggagePropagator {
112115

113116
const { dynamicSamplingContext, traceId, spanId, sampled } = getInjectionData(context);
114117

118+
console.log('3', { existingBaggageHeader, baggage, dynamicSamplingContext, traceId, spanId, sampled });
115119
if (existingBaggageHeader) {
116120
const baggageEntries = parseBaggageHeader(existingBaggageHeader);
117121

@@ -120,6 +124,7 @@ export class SentryPropagator extends W3CBaggagePropagator {
120124
baggage = baggage.setEntry(key, { value });
121125
});
122126
}
127+
console.log('4', { baggageEntries, baggage });
123128
}
124129

125130
if (dynamicSamplingContext) {
@@ -129,14 +134,17 @@ export class SentryPropagator extends W3CBaggagePropagator {
129134
}
130135
return b;
131136
}, baggage);
137+
console.log('5', { dynamicSamplingContext, baggage });
132138
}
133139

134140
// We also want to avoid setting the default OTEL trace ID, if we get that for whatever reason
135141
if (traceId && traceId !== INVALID_TRACEID) {
136142
setter.set(carrier, SENTRY_TRACE_HEADER, generateSentryTraceHeader(traceId, spanId, sampled));
143+
console.log('6', { carrier, traceId, spanId, sampled });
137144
}
138145

139146
super.inject(propagation.setBaggage(context, baggage), carrier, setter);
147+
console.log('7', { carrier });
140148
}
141149

142150
/**
@@ -198,7 +206,7 @@ function getInjectionData(context: Context): {
198206
spanId: string | undefined;
199207
sampled: boolean | undefined;
200208
} {
201-
const span = hasTracingEnabled() ? trace.getSpan(context) : undefined;
209+
const span = trace.getSpan(context);
202210
const spanIsRemote = span?.spanContext().isRemote;
203211

204212
// If we have a local span, we can just pick everything from it

0 commit comments

Comments
 (0)