-
Couldn't load subscription status.
- Fork 849
Description
Package
OpenTelemetry
Package Version
| Package Name | Version |
|---|---|
| OpenTelemetry | 1.10.0 |
Runtime Version
net472;net6.0;net7.0;net8.0
Description
The TraceStateString cannot be controlled by the sampler when the sample decision is PropagationData only, despite it being a tool used during trace propagation.
The below code is wrapped in an if block if (activitySamplingResult != ActivitySamplingResult.PropagationData)
opentelemetry-dotnet/src/OpenTelemetry/Trace/TracerProviderSdk.cs
Lines 518 to 522 in cd31c57
| if (samplingResult.TraceStateString != null) | |
| { | |
| options = options with { TraceState = samplingResult.TraceStateString }; | |
| } | |
Steps to Reproduce
using OpenTelemetry.Trace;
namespace Example;
public sealed class TraceStateAlwaysOffSampler: Sampler {
public override SamplingResult ShouldSample( in SamplingParameters samplingParameters ) {
return new SamplingResult(
decision: SamplingDecision.Drop,
traceStateString: "traces-never-see-this"
);
}
}
Expected Result
I expect to see the TraceStateString on the PropagationData-only Activity object.
Actual Result
The TraceStateString is null after the Activity object receives the Drop decision.
Additional Context
We use the TraceStateString to determine whether a trace is initiated from within our ecosystem or from outside of it. In this way, we can restart traces that originate from 3rd parties, and we can propagate traces that originate from our system.
However, when sampling drops the trace, our TraceStateString no longer gets applied, and so downstream services treat the request as if it's coming from an external party. Those downstream services might then become the root of the trace (which is misleading when that service cannot possibly be the root of a trace).
Because the TraceState is used as part of the trace propagation process (it is included in HTTP Headers for example), the sampler should always set the trace state -- not only when the trace is sampled.