trace: add Random Trace ID Flag#8012
Merged
dmathieu merged 8 commits intoopen-telemetry:mainfrom Mar 13, 2026
Merged
Conversation
Co-authored-by: Joshua MacDonald <jmacd@users.noreply.github.com>
2dbdc5b to
a6b577b
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8012 +/- ##
=====================================
Coverage 81.5% 81.6%
=====================================
Files 304 304
Lines 23444 23452 +8
=====================================
+ Hits 19130 19137 +7
- Misses 3930 3931 +1
Partials 384 384
🚀 New features to boost your workflow:
|
a6b577b to
78be0a5
Compare
Added new features for W3C tracecontext random flag support in TraceFlags and SpanContext.
Contributor
Author
|
FYI, @jmacd |
Contributor
|
Overall, this makes sense to me. Can you share more details about how you will use them? What are you trying to do that needs these? |
Contributor
Author
done. please take a look there. |
dashpole
approved these changes
Mar 11, 2026
Contributor
Author
Member
|
We do need a second approval. |
pellared
reviewed
Mar 12, 2026
Co-authored-by: Robert Pająk <pellared@hotmail.com>
pellared
approved these changes
Mar 12, 2026
Contributor
Author
|
From the contribution guideline, it looks like this is ready to be merged by a maintainer? If so, can someone help to merge? Or let me know what else is needed. Thanks. |
dmathieu
approved these changes
Mar 13, 2026
dmathieu
added a commit
that referenced
this pull request
Apr 3, 2026
Release issue: #8127 ## Added - Add `IsRandom` and `WithRandom` on `TraceFlags`, and `IsRandom` on `SpanContext` in `go.opentelemetry.io/otel/trace` for [W3C Trace Context Level 2 Random Trace ID Flag](https://www.w3.org/TR/trace-context-2/#random-trace-id-flag) support. (#8012) - Add service detection with `WithService` in `go.opentelemetry.io/otel/sdk/resource`. (#7642) - Add `DefaultWithContext` and `EnvironmentWithContext` in `go.opentelemetry.io/otel/sdk/resource` to support plumbing `context.Context` through default and environment detectors. (#8051) - Support attributes with empty value (`attribute.EMPTY`) in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc`. (#8038) - Support attributes with empty value (`attribute.EMPTY`) in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc`. (#8038) - Support attributes with empty value (`attribute.EMPTY`) in `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc`. (#8038) - Support attributes with empty value (`attribute.EMPTY`) in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`. (#8038) - Support attributes with empty value (`attribute.EMPTY`) in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#8038) - Support attributes with empty value (`attribute.EMPTY`) in `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp`. (#8038) - Support attributes with empty value (`attribute.EMPTY`) in `go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest`. (#8038) - Add support for per-series start time tracking for cumulative metrics in `go.opentelemetry.io/otel/sdk/metric`. Set `OTEL_GO_X_PER_SERIES_START_TIMESTAMPS=true` to enable. (#8060) - Add `WithCardinalityLimitSelector` for metric reader for configuring cardinality limits specific to the instrument kind. (#7855) ## Changed - Introduce the `EMPTY` Type in `go.opentelemetry.io/otel/attribute` to reflect that an empty value is now a valid value, with `INVALID` remaining as a deprecated alias of `EMPTY`. (#8038) - Refactor slice handling in `go.opentelemetry.io/otel/attribute` to optimize short slice values with fixed-size fast paths. (#8039) - Improve performance of span metric recording in `go.opentelemetry.io/otel/sdk/trace` by returning early if self-observability is not enabled. (#8067) - Improve formatting of metric data diffs in `go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest`. (#8073) ## Deprecated - Deprecate `INVALID` in `go.opentelemetry.io/otel/attribute`. Use `EMPTY` instead. (#8038) ## Fixed - Return spec-compliant `TraceIdRatioBased` description. This is a breaking behavioral change, but it is necessary to make the implementation [spec-compliant](https://opentelemetry.io/docs/specs/otel/trace/sdk/#traceidratiobased). (#8027) - Fix a race condition in `go.opentelemetry.io/otel/sdk/metric` where the lastvalue aggregation could collect the value 0 even when no zero-value measurements were recorded. (#8056) - Limit HTTP response body to 4 MiB in `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp` to mitigate excessive memory usage caused by a misconfigured or malicious server. Responses exceeding the limit are treated as non-retryable errors. (#8108) - Limit HTTP response body to 4 MiB in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp` to mitigate excessive memory usage caused by a misconfigured or malicious server. Responses exceeding the limit are treated as non-retryable errors. (#8108) - Limit HTTP response body to 4 MiB in `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp` to mitigate excessive memory usage caused by a misconfigured or malicious server. Responses exceeding the limit are treated as non-retryable errors. (#8108) - `WithHostID` detector in `go.opentelemetry.io/otel/sdk/resource` to use full path for `kenv` command on BSD. (#8113) - Fix missing `request.GetBody` in `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp` to correctly handle HTTP2 GOAWAY frame. (#8096) --------- Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds API support for the W3C tracecontext random flag on
TraceFlagsandSpanContextingo.opentelemetry.io/otel/trace:TraceFlags.IsRandom()— reports whether the random bit is setTraceFlags.WithRandom(bool)— sets or clears the random bit in a copy of the flagsSpanContext.IsRandom()— reports whether the random bit is set in the span context's trace flagsThese mirror the existing
IsSampled/WithSampledpattern.Motivation
The W3C Trace Context spec defines a random bit in trace flags to indicate probabilistic sampling. This is required for TraceIdRatioBased sampler 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
thhandling will follow in separate PRs.Co-Author
Joshua MacDonald jmacd@users.noreply.github.com