Skip to content

Conversation

@Gosling-dude
Copy link

@Gosling-dude Gosling-dude commented Dec 24, 2025

What does this change do?

  • Emits a WARNING when TraceIdRatioBasedSampler is configured as a child sampler via ParentBasedSamplerBuilder.
  • Warning is logged once at configuration time only.
  • No runtime or sampling behavior is changed.

Why is this needed?

  • Required by the OpenTelemetry trace SDK specification.
  • Using TraceIdRatioBasedSampler as a child sampler can lead to unexpected behavior.

Implementation notes:

  • Warning logic lives only in ParentBasedSamplerBuilder.
  • ParentBasedSampler remains behavior-only with no logging or side effects.

How was this tested?

  • ./gradlew :sdk:trace:test
  • ./gradlew spotlessCheck

Closes #7790

@Gosling-dude Gosling-dude requested a review from a team as a code owner December 24, 2025 18:09
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Dec 24, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@codecov
Copy link

codecov bot commented Dec 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.10%. Comparing base (1093571) to head (efdcb79).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #7937   +/-   ##
=========================================
  Coverage     90.09%   90.10%           
- Complexity     7432     7438    +6     
=========================================
  Files           834      834           
  Lines         22537    22546    +9     
  Branches       2236     2236           
=========================================
+ Hits          20304    20314   +10     
  Misses         1532     1532           
+ Partials        701      700    -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.

@Gosling-dude Gosling-dude force-pushed the warn-child-traceidratio branch from 6e2eef7 to db30494 Compare December 24, 2025 19:33
@Gosling-dude
Copy link
Author

All required checks are passing.

This implements the spec-required compatibility warning for TraceIdRatioBasedSampler when used as a child sampler. Logging is limited to ParentBasedSamplerBuilder and does not affect sampling behavior.

Happy to adjust if there are any suggestions.

Comment on lines 37 to 43
if (!warnedRemoteParentSampled && remoteParentSampled instanceof TraceIdRatioBasedSampler) {
warnedRemoteParentSampled = true;
logger.warning(
"TraceIdRatioBasedSampler is being used as a child sampler (remoteParentSampled). "
+ "This configuration is discouraged per the OpenTelemetry specification "
+ "and may lead to unexpected sampling behavior.");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is generally only going to be done once for a given builder instance. I don't think we need the extra checks to make sure it only gets logged once.

Copy link
Author

Choose a reason for hiding this comment

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

That makes sense - agreed.

I’ll remove the warned* guards and emit the warning unconditionally when a TraceIdRatioBasedSampler is set as a child sampler. That keeps the builder simpler and aligns with typical usage.

I’ll push a small follow-up update shortly.

Copy link
Author

Choose a reason for hiding this comment

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

It looks like one Windows CI job (windows-latest, 8) failed while the rest passed. This may be transient. would you mind re-running that job when convenient?

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.

Emit warnings when TraceIdRatioBased Sampler is used as child sampler

2 participants