Skip to content

Conversation

@PeterF778
Copy link
Contributor

Adding a new bit definition to TraceFlags.
Adding a method to IdGenerator to declare randomness of the generated trace-ids. Passing the correct TraceFlags to the configured sampler for root spans. Modifying and adding unit tests.

Adding a new bit definition to TraceFlags.
Adding a method to IdGenerator to declare randomness of the generated trace-ids.
Passing the correct TraceFlags to the configured sampler for root spans.
Modifying and adding unit tests.
@PeterF778 PeterF778 requested a review from a team as a code owner January 26, 2026 19:09
@codecov
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

❌ Patch coverage is 92.59259% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.14%. Comparing base (8e332fc) to head (768ad30).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
...in/java/io/opentelemetry/api/trace/TraceFlags.java 80.00% 1 Missing ⚠️
...n/java/io/opentelemetry/sdk/trace/IdGenerator.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8012      +/-   ##
============================================
- Coverage     90.15%   90.14%   -0.01%     
- Complexity     7476     7486      +10     
============================================
  Files           834      834              
  Lines         22540    22566      +26     
  Branches       2236     2238       +2     
============================================
+ Hits          20320    20343      +23     
- Misses         1515     1519       +4     
+ Partials        705      704       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@jack-berg jack-berg linked an issue Jan 27, 2026 that may be closed by this pull request
* generated by a truly random Id generator, otherwise {@code false}. Providing default
* implementation just to maintain compatibility.
*
* @return {@code true} if the samplingrandomTraceId bit is on for this {@link TraceFlags},
Copy link
Member

Choose a reason for hiding this comment

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

Is samplingrandomTraceId supposed to reference a constant?

parentContextForSampler =
preparePrimordialContext(
parentContext,
TraceFlags.getDefault().withRandomTraceIdBit(),
Copy link
Member

@jack-berg jack-berg Jan 27, 2026

Choose a reason for hiding this comment

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

Similar to this comment, we should use singletons here to avoid allocations on the hot path.

Ideally the entire primordial Span / SpanContext would be singletons.

@jack-berg
Copy link
Member

@carlosalberto if you're more in the loop on level 2 span context, any chance you could give this a look over as a sanity check?

}

/**
* Returns a new instance of {@link TraceFlags} whose value is the result of a bitwise OR between
Copy link
Member

@jack-berg jack-berg Jan 27, 2026

Choose a reason for hiding this comment

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

#nit: new may imply object construction. Same advice applies to withSampledBit javadoc.

Suggested change
* Returns a new instance of {@link TraceFlags} whose value is the result of a bitwise OR between
* Returns an instance of {@link TraceFlags} whose value is the result of a bitwise OR between

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 the new W3C random flag.

2 participants