Repository navigation
[CONFIGURATION] Add the probability sampler to file configuration - #4334
Conversation
0f5a749 to
8f1d9fb
Compare
There was a problem hiding this comment.
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
ProbabilitySamplerConfigurationplus parser + visitor wiring for the schema keyprobability/development, withratiodefaulting to1.0. - Adds
SdkBuilder::CreateProbabilitySamplerand updates sampler dispatch to construct aProbabilitySamplerfrom configuration. - Updates composable probability sampler construction to build a composite sampler using
ComposableProbabilitySampler(replacing the priorTraceIdRatioBasedSamplerplaceholder), 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 Report❌ Patch coverage is
Additional details and impacted files@@ 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
🚀 New features to boost your workflow:
|
dbarker
left a comment
There was a problem hiding this comment.
Thanks for the PR! Please see initial feedback below.
…-config # Conflicts: # CHANGELOG.md
There was a problem hiding this comment.
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 toProbabilitySampler), butParseProbabilitySamplerConfigurationnow rejects values outside [0, 1] and returns anInvalidSchemaException(and tests expectDoParse()to return nullptr). This also makesprobability/developmentbehave differently thantrace_id_ratio_basedandcomposable_probability, which currently accept any double forratio. 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
VisitComposableProbabilitynow builds a composite sampler usingComposableProbabilitySamplerinstead of theTraceIdRatioBasedSamplerplaceholder, butVisitComposableProbabilityin this file still callsTraceIdRatioBasedSamplerFactory::Create(model->ratio)(see theVisitComposableProbabilitymethod below this hunk). Either update the implementation to useCompositeSamplerFactory::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);
}
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: newProbabilitySamplerConfiguration,VisitProbability,ParseProbabilitySamplerConfiguration, andSdkBuilder::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 inProbabilitySampler, which warns and uses the spec default.VisitComposableProbabilitynow builds the composite sampler withComposableProbabilitySamplerinstead of theTraceIdRatioBasedSamplerplaceholder.CHANGELOG.mdupdated for non-trivial changes