Skip to content

[CONFIGURATION] Add the probability sampler to file configuration - #4334

Merged
marcalff merged 5 commits into
open-telemetry:mainfrom
ayush-that:probability-sampler-config
Aug 3, 2026
Merged

marcalff merged 5 commits into
open-telemetry:mainfrom
ayush-that:probability-sampler-config

Conversation

@ayush-that

Copy link
Copy Markdown
Contributor

Follow-up to #4135, requested by @dbarker in #4135 (comment).

ref: https://github.com/open-telemetry/opentelemetry-configuration/blob/main/schema/tracer_provider.yaml

Changes

Adds the probability sampler to file configuration under the schema key probability/development: new ProbabilitySamplerConfiguration, VisitProbability, ParseProbabilitySamplerConfiguration, and SdkBuilder::CreateProbabilitySampler. Ratio is optional and defaults to 1.0 per the schema. The parser does not range check the value, same as the other samplers, so validation stays in ProbabilitySampler, which warns and uses the spec default.

VisitComposableProbability now builds the composite sampler with ComposableProbabilitySampler instead of the TraceIdRatioBasedSampler placeholder.

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@ayush-that
ayush-that requested a review from a team as a code owner August 2, 2026 18:26
Copilot AI review requested due to automatic review settings August 2, 2026 18:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds support for configuring the SDK ProbabilitySampler via file (YAML) configuration, aligning the C++ file-configuration surface with the upstream schema and the sampler implementation introduced in the earlier SDK work.

Changes:

  • Introduces ProbabilitySamplerConfiguration plus parser + visitor wiring for the schema key probability/development, with ratio defaulting to 1.0.
  • Adds SdkBuilder::CreateProbabilitySampler and updates sampler dispatch to construct a ProbabilitySampler from configuration.
  • Updates composable probability sampler construction to build a composite sampler using ComposableProbabilitySampler (replacing the prior TraceIdRatioBasedSampler placeholder), and adds/extends unit tests.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
sdk/test/configuration/yaml_trace_test.cc Adds YAML parsing tests for probability/development including default ratio behavior.
sdk/test/configuration/sdk_builder_test.cc Adds unit tests covering CreateProbabilitySampler and ensures composable probability uses CompositeSampler.
sdk/src/configuration/sdk_builder.cc Wires VisitProbability to CreateProbabilitySampler and updates composable probability to use CompositeSamplerFactory + ComposableProbabilitySampler.
sdk/src/configuration/configuration_parser.cc Adds parsing for probability/development and supports optional ratio with default 1.0.
sdk/include/opentelemetry/sdk/configuration/sdk_builder.h Exposes CreateProbabilitySampler in the builder interface.
sdk/include/opentelemetry/sdk/configuration/sampler_configuration_visitor.h Extends the visitor with VisitProbability(...).
sdk/include/opentelemetry/sdk/configuration/probability_sampler_configuration.h New configuration model type for the probability sampler.
sdk/include/opentelemetry/sdk/configuration/configuration_parser.h Declares ParseProbabilitySamplerConfiguration(...).
CHANGELOG.md Records the new configuration capability under Unreleased.

@codecov

codecov Bot commented Aug 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.86%. Comparing base (2beddad) to head (9eedfbe).

Files with missing lines Patch % Lines
sdk/src/configuration/sdk_builder.cc 87.50% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4334      +/-   ##
==========================================
+ Coverage   80.84%   80.86%   +0.02%     
==========================================
  Files         448      450       +2     
  Lines       19161    19186      +25     
==========================================
+ Hits        15489    15513      +24     
- Misses       3672     3673       +1     
Files with missing lines Coverage Δ
.../configuration/probability_sampler_configuration.h 100.00% <100.00%> (ø)
.../sdk/configuration/sampler_configuration_visitor.h 100.00% <ø> (ø)
...lude/opentelemetry/sdk/configuration/sdk_builder.h 100.00% <ø> (ø)
sdk/src/configuration/configuration_parser.cc 78.48% <100.00%> (+0.19%) ⬆️
sdk/src/configuration/sdk_builder.cc 49.65% <87.50%> (+0.31%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbarker dbarker left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR! Please see initial feedback below.

Comment thread sdk/src/configuration/sdk_builder.cc Resolved

@marcalff marcalff left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please see previous comments from @dbarker.

LGTM otherwise.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Suppressed comments (2)

sdk/src/configuration/configuration_parser.cc:1773

  • The PR description says the parser does not range-check ratio (leaving validation to ProbabilitySampler), but ParseProbabilitySamplerConfiguration now rejects values outside [0, 1] and returns an InvalidSchemaException (and tests expect DoParse() to return nullptr). This also makes probability/development behave differently than trace_id_ratio_based and composable_probability, which currently accept any double for ratio. Consider aligning behavior (either remove this range check to match existing samplers + PR description, or add consistent schema-range validation for the other ratio-based samplers too) and update tests accordingly.
  model->ratio = node->GetDouble("ratio", Config::kDefaultRatio);
  if (!(model->ratio >= Config::kMinRatio && model->ratio <= Config::kMaxRatio))
  {
    std::string message("Illegal ratio: ");
    message.append(std::to_string(model->ratio));
    throw InvalidSchemaException(node->Location(), message);
  }

sdk/src/configuration/sdk_builder.cc:469

  • The PR description mentions VisitComposableProbability now builds a composite sampler using ComposableProbabilitySampler instead of the TraceIdRatioBasedSampler placeholder, but VisitComposableProbability in this file still calls TraceIdRatioBasedSamplerFactory::Create(model->ratio) (see the VisitComposableProbability method below this hunk). Either update the implementation to use CompositeSamplerFactory::Create(std::make_shared<ComposableProbabilitySampler>(...)) (and add the needed includes) or adjust the PR description to match the actual behavior.
  void VisitProbability(
      const opentelemetry::sdk::configuration::ProbabilitySamplerConfiguration *model) override
  {
    sampler = sdk_builder_->CreateProbabilitySampler(model);
  }

@dbarker dbarker left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good. Thank you!

@marcalff marcalff left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

@marcalff
marcalff merged commit 4f8c843 into open-telemetry:main Aug 3, 2026
72 checks passed
@ayush-that
ayush-that deleted the probability-sampler-config branch August 21, 2026 15:24
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.

4 participants