Skip to content

[SDK] Enable W3C Trace Context v2#4012

Merged
marcalff merged 13 commits intoopen-telemetry:mainfrom
saphal1998:chore/support-random-id-trace-flag
May 5, 2026
Merged

[SDK] Enable W3C Trace Context v2#4012
marcalff merged 13 commits intoopen-telemetry:mainfrom
saphal1998:chore/support-random-id-trace-flag

Conversation

@saphal1998
Copy link
Copy Markdown
Contributor

@saphal1998 saphal1998 commented Apr 18, 2026

Fixes #2283

Changes

  • Enable W3C Trace Context v2 trace-flag masking in the tracer so the random trace-id flag is preserved.
  • Add test coverage to verify the random flag is handled correctly across trace flags, HTTP trace context propagation, span creation, and OTLP export.

NOTE - Outside of the TraceFlagsTest, I did ask an LLM to determine what other surfaces the random bit would manifest, and the test cases added were suggestions, to me personally, these surfaces made sense, but I could be missing critical tests that I need to add or perhaps these tests are redundant, so please let me know!

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@saphal1998 saphal1998 requested a review from a team as a code owner April 18, 2026 19:52
@saphal1998 saphal1998 marked this pull request as draft April 18, 2026 19:52
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.04%. Comparing base (f2bc1e7) to head (1f4c0cd).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4012      +/-   ##
==========================================
+ Coverage   82.04%   82.04%   +0.01%     
==========================================
  Files         385      385              
  Lines       15895    15896       +1     
==========================================
+ Hits        13039    13040       +1     
  Misses       2856     2856              
Files with missing lines Coverage Δ
sdk/src/trace/tracer.cc 86.12% <ø> (ø)

... and 1 file with indirect coverage changes

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

@saphal1998
Copy link
Copy Markdown
Contributor Author

saphal1998 commented Apr 20, 2026

@marcalff I'm a little unsure as to why checks that fail, actually fail, could you perhaps point me to what might have triggered these failures? thank you for the help!

@marcalff
Copy link
Copy Markdown
Member

@marcalff I'm a little unsure as to why checks that fail, actually fail, could you perhaps point me to what might have triggered these failures? thank you for the help!

From the IWYU CI logs:

include-what-you-use reported 1 warning(s) exceeding the existing warning limit of 0 with cmake options preset 'all-options-abiv1-preview'

This is only a summary.

In this case, see the section iwyu_tool in the logs, to see the actual errors.

Warning: include-what-you-use reported diagnostics:

/home/runner/work/opentelemetry-cpp/opentelemetry-cpp/sdk/test/trace/tracer_test.cc should add these lines:
#include "opentelemetry/trace/trace_flags.h"

Note that the build continues on failures (make -k), to report as many as possible in one run, which is why we have to search for each issue then.

@marcalff
Copy link
Copy Markdown
Member

@saphal1998

The magic text to look for in logs, in the iwyu_tool section, is:

Warning: include-what-you-use reported diagnostics:

@marcalff
Copy link
Copy Markdown
Member

@saphal1998

For the build, please fix include-what-you-use as indicated earlier.

For testing, see the existing CI:

  w3c_trace_context_compliance_v1:
    name: W3C Distributed Tracing Validation V1

and add the same for level 2 validation.

See also the following directory for tooling: ext/test/w3c_tracecontext_http_test_server.

Comment thread api/include/opentelemetry/trace/trace_flags.h Outdated
@saphal1998 saphal1998 marked this pull request as ready for review April 29, 2026 14:31
@saphal1998 saphal1998 requested a review from marcalff April 30, 2026 15:35
Comment thread sdk/src/trace/tracer.cc
Copy link
Copy Markdown
Member

@marcalff marcalff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the good test coverage.

@marcalff marcalff changed the title [SDK] Use kAllW3CTraceContext2Flags [SDK] Enable W3C Trace Context v2 May 5, 2026
@marcalff marcalff merged commit 99300d1 into open-telemetry:main May 5, 2026
70 checks passed
malkia added a commit to malkia/opentelemetry-cpp that referenced this pull request May 6, 2026
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.

Support for "random trace id" flag in trace context

3 participants