Skip to content

Child spans inherit the parent’s TraceFlags::kIsSampled bit even when the active sampler returns Decision::DROP #3725

@SurvivorofChaos

Description

@SurvivorofChaos

Describe your environment
Ubuntu22.04
OpenTelemetry-cpp v1.22.0

Steps to reproduce

  1. Process1: Start a span, and set it to active, as parent, propogate(IsSampled=true)
  2. Process2: Start a child span, with custom sampler, which returns Decision::DROP
  3. Check the child span trace flag, it would be true

What is the expected behavior?
Per the spec, TraceFlags::kIsSampled must reflect the sampler decision.
Dropped spans should have the sampled bit unset.

What is the actual behavior?
The child span always get the same IsSampled()=true if the parent is sampled, no matter what the custom sampler returns.

Root Cause
The code copies the parent’s flags (see this line) and only sets the sampled bit when ShouldSample returns RECORD_AND_SAMPLE(see this line). It never clears the bit for DROP/RECORD_ONLY. When a drop decision occurs, the SDK still creates a SpanContext with kIsSampled set and wraps it in a NoopSpan, so span->GetContext().IsSampled() remains true.

Tip: React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage/acceptedIndicates an issue or PR is ready to be actively worked on.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions