Skip to content

Attributes added by sampler cannot be populated on activity #953

@lmolkova

Description

@lmolkova

[renamed]

Describe your environment. Describe any aspect of your environment relevant to the problem:
N/A

  • SDK version: (nuget versions of the all the relevant packages)
    0.4.0-beta

  • .NET runtime version (.NET or .NET Core, TargetFramework in the .csproj file):
    N/A (any)

  • Platform and OS version:
    any

Steps to reproduce.

  • configure probability sampling
  • create activities without a parent
  • random id will be generated
  • sampling decision will be made based on random trace id
  • trace id will not be set on activity

internal static ActivityDataRequest ComputeActivityDataRequest(
in ActivityCreationOptions<ActivityContext> options,
Sampler sampler)
{
var isRootSpan = options.Parent.TraceId == default;
// This is not going to be the final traceId of the Activity (if one is created), however, it is
// needed in order for the sampling to work. This differs from other OTel SDKs in which it is
// the Sampler always receives the actual traceId of a root span/activity.
ActivityTraceId traceId = !isRootSpan
? options.Parent.TraceId
: ActivityTraceId.CreateRandom();
var samplingParameters = new SamplingParameters(
options.Parent,
traceId,
options.Name,
options.Kind,
options.Tags,
options.Links);
var shouldSample = sampler.ShouldSample(samplingParameters);
if (shouldSample.IsSampled)
{
return ActivityDataRequest.AllDataAndRecorded;
}
// If it is the root span select PropagationData so the trace ID is preserved
// even if no activity of the trace is recorded (sampled per OpenTelemetry parlance).
return isRootSpan
? ActivityDataRequest.PropagationData
: ActivityDataRequest.None;
}
}

We need a way to pass back trace-id if it was created and attributes that were set by sampler to comply with the spec along with sampling decision.

What is the expected behavior?
Trace-id used to make sampling decision should be reused for consistent sampling across services. Attributes set by sampler should also be propagated back from sampler (see spec).

What is the actual behavior?

Trace id will not be set on the activity (i.e. sampling result will be independent of trace-id and non-deterministic). Old PR about probability sampling suggests we determinism
Assuming another service downstream has a different sampling configuration and would need to recalculate sampling hash - it will create inconsistent sampling decisions between upstream and downstream.

Thoughts? @tarekgh @cijothomas @reyang

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpkg:OpenTelemetryIssues related to OpenTelemetry NuGet package

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions