Skip to content

Conversation

@anuraaga
Copy link
Contributor

@anuraaga anuraaga requested a review from a team as a code owner August 29, 2025 07:29
@codecov
Copy link

codecov bot commented Aug 29, 2025

Codecov Report

❌ Patch coverage is 96.85864% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.07%. Comparing base (63d4617) to head (c5ebbb6).
⚠️ Report is 34 commits behind head on main.

Files with missing lines Patch % Lines
...nsion/incubator/trace/samplers/OtelTraceState.java 94.44% 2 Missing and 3 partials ⚠️
...ion/incubator/trace/samplers/CompositeSampler.java 97.14% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #7626      +/-   ##
============================================
+ Coverage     89.99%   90.07%   +0.08%     
- Complexity     7079     7172      +93     
============================================
  Files           803      812       +9     
  Lines         21412    21653     +241     
  Branches       2086     2123      +37     
============================================
+ Hits          19269    19504     +235     
- Misses         1479     1480       +1     
- Partials        664      669       +5     

☔ 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.

@trask
Copy link
Member

trask commented Sep 4, 2025

cc @PeterF778 @oertl

Attributes attributes,
List<LinkData> parentLinks) {
TraceState traceState = Span.fromContext(parentContext).getSpanContext().getTraceState();
OtelTraceState otTraceState = OtelTraceState.parse(traceState);
Copy link
Contributor

Choose a reason for hiding this comment

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

teency nit: rename to otelTraceState so as to not confuse my poor brain between this and openTracing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought by now we may have been past that but guess not ;)

otTraceState.getRandomValue(), INVALID_THRESHOLD, otTraceState.getRest());
}

String ot = otTraceState.serialize();
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe rename to "seralizedState"?

@jkwatson
Copy link
Contributor

jkwatson commented Sep 8, 2025

Seems like this would be an excellent target for some property-based tests. I can't remember if we have any in here already, but it might be a good opportunity, since we can very clearly define the invariants, and generate random inputs, verifying the outputs match the expectations.

@anuraaga
Copy link
Contributor Author

anuraaga commented Sep 9, 2025

Thanks - we have fuzz tests already which I think are basically what you're getting at. Sounds good will add some

@jkwatson
Copy link
Contributor

jkwatson commented Sep 9, 2025

Thanks - we have fuzz tests already which I think are basically what you're getting at. Sounds good will add some

Fuzz testing is slightly different, in that the goal is usually just to make sure that things don't break, rather than testing invariants, but if you can use the same framework to accomplish property testing, that would be awesome.

boolean sampled = false;
if (isValidThreshold(intent.getThreshold())) {
thresholdReliable = intent.isThresholdReliable();
long randomValue;
Copy link
Contributor

Choose a reason for hiding this comment

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

If the threshold is not reliable, the sampler must not use the random value from the trace state or from the trace-id. This is because we cannot guarantee that these "random" values have the required uniform distribution over the (MIN_THRESHOLD, MAX_THRESHOLD) interval.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't find anything in the spec on this. I noticed the caveat to deal with rate limiting sampler but since that's also not in the spec went with the simpler implementation. Is this something to change now or can we follow up after spec clarification?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok went ahead and switched to generating a random when unreliable

boolean sampled = false;
if (isValidThreshold(intent.getThreshold())) {
thresholdReliable = intent.isThresholdReliable();
long randomValue;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok went ahead and switched to generating a random when unreliable

Attributes attributes,
List<LinkData> parentLinks) {
TraceState traceState = Span.fromContext(parentContext).getSpanContext().getTraceState();
OtelTraceState otTraceState = OtelTraceState.parse(traceState);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought by now we may have been past that but guess not ;)

assertState(output, rv, th);
}

private static void assertState(OtelTraceState state, long rv, long th) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jkwatson This is what I came up with for testing properties based on fuzz. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I can't say I grok all the assertions, but this looks good! Thanks!

@anuraaga
Copy link
Contributor Author

@jkwatson Think we can proceed with this PR, or anything I should look at? Thanks

@jkwatson
Copy link
Contributor

@jkwatson Think we can proceed with this PR, or anything I should look at? Thanks

If @PeterF778 can give it a 👍🏽 then I think we're good to go.

Copy link
Contributor

@PeterF778 PeterF778 left a comment

Choose a reason for hiding this comment

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

Looks nice and clean, thanks!

Copy link
Contributor

@jkwatson jkwatson left a comment

Choose a reason for hiding this comment

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

Thanks!

@jkwatson jkwatson merged commit 74bc3bd into open-telemetry:main Sep 18, 2025
29 checks passed
@otelbot
Copy link
Contributor

otelbot bot commented Sep 18, 2025

Thank you for your contribution @anuraaga! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey.

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.

Experimental composite sampler

4 participants