Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] TraceStateString is not set when the sampler returns SamplingDecision.Drop #6054

Open
jordankay13 opened this issue Jan 9, 2025 · 0 comments
Labels
bug Something isn't working needs-triage New issues which have not been classified or triaged by a community member pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package

Comments

@jordankay13
Copy link

jordankay13 commented Jan 9, 2025

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)

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.

@jordankay13 jordankay13 added bug Something isn't working needs-triage New issues which have not been classified or triaged by a community member labels Jan 9, 2025
@github-actions github-actions bot added the pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package label Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage New issues which have not been classified or triaged by a community member pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package
Projects
None yet
Development

No branches or pull requests

1 participant