You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2026-06-03 18:35:08 +02:00
2ffde5a428
## Summary Adds API support for the W3C tracecontext random flag on `TraceFlags` and `SpanContext` in `go.opentelemetry.io/otel/trace`: - **`TraceFlags.IsRandom()`** — reports whether the random bit is set - **`TraceFlags.WithRandom(bool)`** — sets or clears the random bit in a copy of the flags - **`SpanContext.IsRandom()`** — reports whether the random bit is set in the span context's trace flags These mirror the existing `IsSampled` / `WithSampled` pattern. ## Motivation The W3C Trace Context spec defines a random bit in trace flags to indicate probabilistic sampling. This is required for [TraceIdRatioBased sampler](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#traceidratiobased) support, where the random bit is set when a trace is probabilistically sampled and is used for extrapolated span metrics. ## Related Part of #7928 (Support TraceIdRatioBased Sampler). This PR adds the trace API needed for that work; sampler implementation and tracestate `th` handling will follow in separate PRs. ## Co-Author Joshua MacDonald <jmacd@users.noreply.github.com> --------- Co-authored-by: Joshua MacDonald <jmacd@users.noreply.github.com> Co-authored-by: Robert Pająk <pellared@hotmail.com> Co-authored-by: Damien Mathieu <42@dmathieu.com>