Skip to content

Restrict upgrade of sample decision in composite sampler#13

Merged
thumbrise merged 1 commit into
mainfrom
8-compositesampler-allows-later-samplers-to-upgrade-recordonly-to-recordandsample
Mar 18, 2026
Merged

Restrict upgrade of sample decision in composite sampler#13
thumbrise merged 1 commit into
mainfrom
8-compositesampler-allows-later-samplers-to-upgrade-recordonly-to-recordandsample

Conversation

@thumbrise

@thumbrise thumbrise commented Mar 18, 2026

Copy link
Copy Markdown
Owner

Summary

Fix CompositeSampler to enforce restrict-only semantics: later samplers can only
restrict the sampling decision, never upgrade it.

Problem

CompositeSampler used a "last wins" strategy — the loop unconditionally overwrote
the result with each sampler's decision, only short-circuiting on Drop. This allowed
a later sampler to upgrade a prior restriction:
RecordOnly → RecordAndSample → final: RecordAndSample (wrong)

Solution

The loop now tracks the strictest (minimum) decision seen so far, using the OTel SDK's
enum ordering (Drop < RecordOnly < RecordAndSample). A later sampler can only tighten
the decision, never loosen it:
RecordOnly → RecordAndSample → final: RecordOnly (correct)

Tests

  • RecordOnly then RecordAndSample → expects RecordOnly (no upgrade)
  • RecordAndSample then RecordOnly → expects RecordOnly (downgrade)
  • Both RecordAndSample → expects RecordAndSample (unchanged)
  • RecordAndSample then Drop → expects Drop
  • No samplers → expects Drop
  • Description output for zero and multiple samplers
  • Guard test asserting OTel SamplingDecision enum ordering

Breaking Change

Callers relying on the old "last sampler wins" behavior will see different results.
This is intentional — the old behavior was a bug.

@thumbrise thumbrise marked this pull request as ready for review March 18, 2026 16:13

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@thumbrise thumbrise force-pushed the 8-compositesampler-allows-later-samplers-to-upgrade-recordonly-to-recordandsample branch from f2ed0bb to 29b688c Compare March 18, 2026 16:34
Comment thread signal/trace/composite_sampler.go
Comment thread signal/trace/composite_sampler_test.go
@thumbrise thumbrise merged commit 338b603 into main Mar 18, 2026
13 checks passed
@thumbrise thumbrise deleted the 8-compositesampler-allows-later-samplers-to-upgrade-recordonly-to-recordandsample branch March 18, 2026 16:56
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 0.1.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CompositeSampler allows later samplers to upgrade RecordOnly to RecordAndSample

2 participants