Skip to content

sdk/trace: TraceIDRatioBased sampler with tracestate support#8059

Draft
yuanyuanzhao3 wants to merge 2 commits intoopen-telemetry:mainfrom
yuanyuanzhao3:traceidratio-sampler
Draft

sdk/trace: TraceIDRatioBased sampler with tracestate support#8059
yuanyuanzhao3 wants to merge 2 commits intoopen-telemetry:mainfrom
yuanyuanzhao3:traceidratio-sampler

Conversation

@yuanyuanzhao3
Copy link
Contributor

Description

Implements the TraceIDRatioBased sampler with OpenTelemetry tracestate support per the TraceState: Probability Sampling specification.

Part of #7928 (Support TraceIdRatioBased Sampler).

Changes

TraceIDRatioBased sampler

  • Tracestate ot key: When sampling, encodes the rejection threshold in the th sub-key (e.g. th:8 for 50% sampling).
  • Randomness sources: Uses explicit randomness from the rv sub-key when present; otherwise uses the least-significant 56 bits of the TraceID (per W3C Trace Context Level 2).
  • Threshold erasure: When the trace ID is not marked random (FlagsRandom), the sampler erases the th value in tracestate, as required for unknown sampling probability.

AlwaysOn sampler

  • Updates tracestate with th:0 when sampling to indicate 100% sampling probability.

Testing

  • TestTracestateRandomness: Parsing of the rv sub-key.
  • TestEraseTraceStateThKeyValue: Erasure of th in all positions.
  • TestInsertOrUpdateTraceStateThKeyValue: Insert/update of th.
  • TestTraceIDRatioSamplerShouldSample: Sampling behavior with tracestate.
  • TestTracestateIsPassed: Tracestate propagation across samplers.
  • TestTraceIdRatioSamplesInclusively: TraceIDRatioBased inclusion property.

Related

Co-Author

Joshua MacDonald jmacd@users.noreply.github.com

Co-authored-by: Joshua MacDonald <jmacd@users.noreply.github.com>
@yuanyuanzhao3 yuanyuanzhao3 marked this pull request as draft March 13, 2026 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant