Skip to content

[SDK] Use kAllW3CTraceContext2Flags#4012

Draft
saphal1998 wants to merge 9 commits intoopen-telemetry:mainfrom
saphal1998:chore/support-random-id-trace-flag
Draft

[SDK] Use kAllW3CTraceContext2Flags#4012
saphal1998 wants to merge 9 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.06%. Comparing base (dbf6567) to head (44f9bfc).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4012      +/-   ##
==========================================
+ Coverage   82.06%   82.06%   +0.01%     
==========================================
  Files         385      385              
  Lines       15891    15892       +1     
==========================================
+ Hits        13039    13040       +1     
  Misses       2852     2852              
Files with missing lines Coverage Δ
api/include/opentelemetry/trace/trace_flags.h 100.00% <ø> (ø)
sdk/src/trace/tracer.cc 86.12% <ø> (ø)
🚀 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.

#include <cstdint>

#include "opentelemetry/nostd/span.h"
#include "opentelemetry/trace/trace_flags.h"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is the root cause of the new clang-tidy warning, which breaks CI.

This header file includes itself, remove.

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

2 participants