Repository navigation
feat(sdk): support trace sampler environment variables - #4729
Open
Rajkaran-122 wants to merge 4 commits into
Open
Rajkaran-122 wants to merge 4 commits into
Rajkaran-122 wants to merge 4 commits into
Conversation
Implement OTEL_TRACES_SAMPLER and OTEL_TRACES_SAMPLER_ARG environment variables to configure the trace sampler. This allows users to configure sampling behavior without code changes. Supported sampler values: - always_on - always_off - traceidratio - parentbased_traceidratio - parentbased_always_on - parentbased_always_off For ratio-based samplers (traceidratio, parentbased_traceidratio), the ratio is specified via OTEL_TRACES_SAMPLER_ARG (default 1.0 if unset). Implementation details: - Added sampler_env.h/cc with GetSamplerFromEnv() function - Updated TracerProvider and TracerContext constructors to use environment-based sampler when no explicit sampler is provided - Updated TracerProviderFactory and TracerContextFactory to use environment-based sampler - Invalid sampler names or ratios fall back to AlwaysOnSampler with a warning - Explicitly supplied samplers always take precedence over environment variables - Added comprehensive unit tests covering all supported values, edge cases, and error conditions Closes open-telemetry#4709
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4729 +/- ##
==========================================
+ Coverage 86.69% 86.74% +0.05%
==========================================
Files 527 528 +1
Lines 20902 20958 +56
==========================================
+ Hits 18119 18178 +59
+ Misses 2783 2780 -3
🚀 New features to boost your workflow:
|
… env vars ParentBasedSamplerFactory::Create() expects shared_ptr but sampler factories return unique_ptr. Convert ownership correctly using release() and shared_ptr constructor for all parent-based sampler variants. Also adds test coverage for invalid ratio validation in parentbased_traceidratio and fixes comment line length formatting.
Rajkaran-122
force-pushed
the
feat/sdk-trace-sampler-env-vars
branch
from
October 23, 2026 14:03
42e557f to
61c535d
Compare
Resolves conflicts in CHANGELOG.md and tracer_provider.cc by keeping sampler environment variable integration.
mateenali66
reviewed
Oct 24, 2026
mateenali66
left a comment
Member
There was a problem hiding this comment.
ran it at ad74150f. unset matches main on all three paths, and the six values reach the constructors and both factories. a few things:
parentbased_traceidratiowith an out of range arg (1.5,-0.5,nan) returns plainAlwaysOnSampler, so a child of an unsampled remote parent gets sampled. the spec says an invalid arg MUST be ignored as if unset, which is ratio 1.0 with the wrapper kept.0.5abcalready ends up there, so the two invalid paths disagree.- names are matched case sensitively, so
ALWAYS_OFFsamples everything. the spec says enum values SHOULD be case-insensitive, andmeter_context.ccalready does it for the exemplar filter.CaseInsensitiveSamplerNamespasses either way. - no test sets the variable and then builds a provider or context.
CHANGELOG.md:921has a leftover>>>>>>> upstream/main, and the Windows jobs needenv_variables.hin the test forsetenv.
Rajkaran-122
force-pushed
the
feat/sdk-trace-sampler-env-vars
branch
from
October 24, 2026 20:14
7bb4b61 to
3c9d85e
Compare
- Fix invalid ratio handling for parentbased_traceidratio: use default ratio of 1.0 instead of falling back to AlwaysOnSampler, ensuring unsampled remote parents remain unsampled - Make sampler-name matching case-insensitive as recommended by OpenTelemetry specification - Add regression tests for invalid ratios (1.5, -0.5, nan, malformed 0.5abc) with parentbased_traceidratio - Add tests verifying unsampled remote parent remains unsampled with invalid arguments - Add tests for case-insensitive sampler names (ALWAYS_ON, ALWAYS_OFF, TRACEIDRATIO, PARENTBASED_ALWAYS_ON) - Add integration tests verifying TracerContext and TracerProvider use env sampler when none provided, and prefer explicit sampler over env - Include env_variables.h in test for Windows CI compatibility - Remove stray merge-conflict marker from CHANGELOG.md
Rajkaran-122
force-pushed
the
feat/sdk-trace-sampler-env-vars
branch
from
October 24, 2026 22:04
3c9d85e to
dd1b751
Compare
Member
|
re-ran at dd1b751. points 1, 2 and 4 are fixed. still open:
|
This branch has not been deployed
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.
Implement OTEL_TRACES_SAMPLER and OTEL_TRACES_SAMPLER_ARG environment variables to configure the trace sampler. This allows users to configure sampling behavior without code changes.
Supported sampler values:
For ratio-based samplers (traceidratio, parentbased_traceidratio), the ratio is specified via OTEL_TRACES_SAMPLER_ARG (default 1.0 if unset).
Implementation details:
Closes #4709