Skip to content

feat: add LAST9_TRACE_SAMPLE_RATE env var for probabilistic sampling - #16

Merged
ashishl9 merged 1 commit into
mainfrom
feat/probabilistic-sampling-env
Feb 23, 2026
Merged

feat: add LAST9_TRACE_SAMPLE_RATE env var for probabilistic sampling#16
ashishl9 merged 1 commit into
mainfrom
feat/probabilistic-sampling-env

Conversation

@prathamesh-sonpatki

Copy link
Copy Markdown
Member

Summary

  • Adds LAST9_TRACE_SAMPLE_RATE env var (0.0–1.0) that maps to parentbased_traceidratio sampler
  • Takes precedence over OTEL_TRACES_SAMPLER / OTEL_TRACES_SAMPLER_ARG when set
  • Simplifies sampling configuration: LAST9_TRACE_SAMPLE_RATE=0.5 → sample 50% of traces

Details

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_traceidratio internally, 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-numeric
  • TestLoad_SampleRate — validates config loading: unset, set to 0.5, set to 0, invalid
  • TestSampleRateOverridesSampler — verifies LAST9_TRACE_SAMPLE_RATE overrides OTEL_TRACES_SAMPLER
  • TestSampleRateUnsetFallsBackToSampler — verifies fallback when unset
  • Lint clean (golangci-lint run --timeout=5m ./...)

Resolves: FDE-49

🤖 Generated with Claude Code

…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 ashishl9 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.

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

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.

@ashishl9
ashishl9 merged commit 8288d51 into main Feb 23, 2026
10 checks passed
@prathamesh-sonpatki
prathamesh-sonpatki deleted the feat/probabilistic-sampling-env branch April 7, 2026 10:04
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.

2 participants