feat: add LAST9_TRACE_SAMPLE_RATE env var for probabilistic sampling - #16
Merged
Conversation
…ling Add a simple env var that maps directly to parentbased_traceidratio, removing the need to understand OTEL_TRACES_SAMPLER and OTEL_TRACES_SAMPLER_ARG. When set, it takes precedence over the standard OTel sampler env vars. Example: LAST9_TRACE_SAMPLE_RATE=0.5 samples 50% of new traces while respecting parent sampling decisions. Resolves: FDE-49 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ashishl9
approved these changes
Feb 23, 2026
ashishl9
left a comment
Contributor
There was a problem hiding this comment.
LGTM!
✅ Clean implementation of that simplifies sampling configuration
✅ Proper precedence logic - takes priority over as documented
✅ Comprehensive test coverage - parsing validation, config loading, precedence, and fallback behavior
✅ Clear error handling - invalid values logged and gracefully ignored
✅ Excellent documentation - both in code comments and PR description
The parentbased_traceidratio approach correctly respects parent sampling decisions while allowing local rate control.
ashishl9
approved these changes
Feb 23, 2026
ashishl9
left a comment
Contributor
There was a problem hiding this comment.
LGTM!
The implementation is clean and well-tested:
- Simple configuration via LAST9_TRACE_SAMPLE_RATE (0.0-1.0)
- Proper precedence over OTEL_TRACES_SAMPLER
- Comprehensive test coverage for parsing, loading, precedence, and fallback
- Clear error handling for invalid values
- Excellent documentation
The parentbased_traceidratio approach correctly respects parent sampling decisions while allowing local rate control.
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LAST9_TRACE_SAMPLE_RATEenv var (0.0–1.0) that maps toparentbased_traceidratiosamplerOTEL_TRACES_SAMPLER/OTEL_TRACES_SAMPLER_ARGwhen setLAST9_TRACE_SAMPLE_RATE=0.5→ sample 50% of tracesDetails
The standard OTel approach requires setting two env vars (
OTEL_TRACES_SAMPLER=parentbased_traceidratio+OTEL_TRACES_SAMPLER_ARG=0.5) and understanding sampler types. This adds a single, discoverable alternative.Precedence:
LAST9_TRACE_SAMPLE_RATE>OTEL_TRACES_SAMPLER> default (always_on)Behavior: Uses
parentbased_traceidratiointernally, which respects parent sampling decisions — if a parent service already sampled the trace, the child will honor it regardless of the local sample rate.Invalid values (negative, >1.0, non-numeric) are logged as warnings and ignored, falling back to
OTEL_TRACES_SAMPLER.Test plan
TestParseSampleRate— validates parsing: empty, 0.0, 0.5, 1.0, negative, >1.0, non-numericTestLoad_SampleRate— validates config loading: unset, set to 0.5, set to 0, invalidTestSampleRateOverridesSampler— verifies LAST9_TRACE_SAMPLE_RATE overrides OTEL_TRACES_SAMPLERTestSampleRateUnsetFallsBackToSampler— verifies fallback when unsetgolangci-lint run --timeout=5m ./...)Resolves: FDE-49
🤖 Generated with Claude Code