Skip to content

Feat: Have SpanContext support the new W3C random flag. - #7834

Merged
dmathieu merged 15 commits into
open-telemetry:mainfrom
nikhilmantri0902:feat/support_w3c_random_flag
Mar 4, 2026
Merged

Feat: Have SpanContext support the new W3C random flag.#7834
dmathieu merged 15 commits into
open-telemetry:mainfrom
nikhilmantri0902:feat/support_w3c_random_flag

Conversation

@nikhilmantri0902

Copy link
Copy Markdown
Contributor

Problem

  • The Go SDK masks trace flags to the sampled bit and rejects version 00 flags > 0x02.
  • This drops the W3C Trace Context Level 2 random Trace ID flag (0x02) and any forward-compatible bits.

Approach

  • Treat trace flags as an 8-bit bitmask across extract, storage, and inject.
  • Accept any flags for traceparent version 00 and preserve them unchanged.
  • Interpret only known bits for behavior (sampling uses 0x01); do not change sampling logic.

Implementation details

  • propagation/trace_context.go
    • Inject: emit sc.TraceFlags() without masking.
    • Extract: remove opts[0] > 2 rejection; store full flags byte in SpanContextConfig.TraceFlags.
  • propagation/trace_context_test.go
    • Add extract cases for 0x02 and 0x03; ensure 0x09 is preserved.
    • Remove "unused bits set" from invalid cases.
    • Inject cases preserve 0xff, 0x02, and 0x03.
    • Future-version flag tests now expect full byte, not masked.

Closes #7635

@codecov

codecov Bot commented Jan 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.6%. Comparing base (edba765) to head (47af92a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #7834   +/-   ##
=====================================
  Coverage   81.6%   81.6%           
=====================================
  Files        304     304           
  Lines      23384   23385    +1     
=====================================
+ Hits       19090   19091    +1     
+ Misses      3906    3905    -1     
- Partials     388     389    +1     
Files with missing lines Coverage Δ
propagation/trace_context.go 97.0% <100.0%> (+<0.1%) ⬆️
trace/trace.go 98.2% <ø> (ø)

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
@nikhilmantri0902

Copy link
Copy Markdown
Contributor Author

Hi @dmathieu can you review this.

Comment thread propagation/trace_context.go
@MrAlias MrAlias added this to the v1.41.0 milestone Feb 19, 2026
Comment thread propagation/trace_context.go
@MrAlias MrAlias modified the milestones: v1.41.0, v1.42.0 Feb 26, 2026
Comment thread CHANGELOG.md Outdated
Co-authored-by: Damien Mathieu <42@dmathieu.com>
@nikhilmantri0902

Copy link
Copy Markdown
Contributor Author

accepted ur suggested change @dmathieu. We can merge this I think now.

@dmathieu
dmathieu merged commit 8c91c83 into open-telemetry:main Mar 4, 2026
33 checks passed
pellared added a commit that referenced this pull request Mar 6, 2026
### Added

- Add `go.opentelemetry.io/otel/semconv/v1.40.0` package.
The package contains semantic conventions from the `v1.40.0` version of
the OpenTelemetry Semantic Conventions.
See the [migration documentation](./semconv/v1.40.0/MIGRATION.md) for
information on how to upgrade from
`go.opentelemetry.io/otel/semconv/v1.39.0`. (#7985)
- Add `Err` and `SetErr` on `Record` in `go.opentelemetry.io/otel/log`
to attach an error and set record exception attributes in
`go.opentelemetry.io/otel/log/sdk`. (#7924)

### Changed

- `TracerProvider.ForceFlush` in `go.opentelemetry.io/otel/sdk/trace`
joins errors together and continues iteration through SpanProcessors as
opposed to returning the first encountered error without attempting
exports on subsequent SpanProcessors. (#7856)

### Fixed

- Fix missing `request.GetBody` in
`go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp` to
correctly handle HTTP2 GOAWAY frame. (#7931)
- Fix semconv v1.39.0 generated metric helpers skipping required
attributes when extra attributes were empty. (#7964)
- Preserve W3C TraceFlags bitmask (including the random Trace ID flag)
during trace context extraction and injection in
`go.opentelemetry.io/otel/propagation`. (#7834)

### Removed

- Drop support for [Go 1.24]. (#7984)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants