Skip to content

Commit a906b9a

Browse files
committed
rewrite method
1 parent c9dde6a commit a906b9a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

packages/opentelemetry/src/utils/dynamicSamplingContext.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ export function getDynamicSamplingContextFromSpan(span: AbstractSpan): Readonly<
2424
return {};
2525
}
2626

27-
const dsc = getDynamicSamplingContextFromClient(span.spanContext().traceId, client);
28-
2927
const traceState = span.spanContext().traceState;
3028
const traceStateDsc = traceState?.get(SENTRY_TRACE_STATE_DSC);
3129

32-
if (traceStateDsc) {
33-
const dsc = baggageHeaderToDynamicSamplingContext(traceStateDsc);
34-
if (dsc) {
35-
return dsc;
36-
}
30+
// If the span has a DSC, we want it to take precedence
31+
const dscOnSpan = traceStateDsc ? baggageHeaderToDynamicSamplingContext(traceStateDsc) : undefined;
32+
33+
if (dscOnSpan) {
34+
return dscOnSpan;
3735
}
3836

37+
const dsc = getDynamicSamplingContextFromClient(span.spanContext().traceId, client);
38+
3939
const attributes = spanHasAttributes(span) ? span.attributes : {};
4040

4141
const sampleRate = attributes[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE];
@@ -51,6 +51,7 @@ export function getDynamicSamplingContextFromSpan(span: AbstractSpan): Readonly<
5151
dsc.transaction = name;
5252
}
5353

54+
// TODO: Once we aligned span types, use spanIsSampled() from core instead
5455
// eslint-disable-next-line no-bitwise
5556
const sampled = Boolean(span.spanContext().traceFlags & TraceFlags.SAMPLED);
5657
dsc.sampled = String(sampled);

0 commit comments

Comments
 (0)