From 9846e83d17ccdbfca142256be4c42696cb787631 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Wed, 5 Aug 2026 15:07:39 -0400 Subject: [PATCH 01/20] add sdk logs component builders --- .../sdk/configuration/logs_builders.h | 19 ++ sdk/src/configuration/logs_builders.cc | 176 ++++++++++++++++++ 2 files changed, 195 insertions(+) create mode 100644 sdk/include/opentelemetry/sdk/configuration/logs_builders.h create mode 100644 sdk/src/configuration/logs_builders.cc diff --git a/sdk/include/opentelemetry/sdk/configuration/logs_builders.h b/sdk/include/opentelemetry/sdk/configuration/logs_builders.h new file mode 100644 index 0000000000..29bdf7dfe1 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/logs_builders.h @@ -0,0 +1,19 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/registry.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +void RegisterDefaultLogsBuilders(Registry *registry); + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/configuration/logs_builders.cc b/sdk/src/configuration/logs_builders.cc new file mode 100644 index 0000000000..e29f8e4803 --- /dev/null +++ b/sdk/src/configuration/logs_builders.cc @@ -0,0 +1,176 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/sdk/configuration/logs_builders.h" + +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/logs/severity.h" +#include "opentelemetry/sdk/configuration/batch_log_record_processor_builder.h" +#include "opentelemetry/sdk/configuration/batch_log_record_processor_configuration.h" +#include "opentelemetry/sdk/configuration/logger_config_configuration.h" +#include "opentelemetry/sdk/configuration/logger_configurator_builder.h" +#include "opentelemetry/sdk/configuration/logger_configurator_configuration.h" +#include "opentelemetry/sdk/configuration/logger_matcher_and_config_configuration.h" +#include "opentelemetry/sdk/configuration/registry.h" +#include "opentelemetry/sdk/configuration/severity_number.h" +#include "opentelemetry/sdk/configuration/simple_log_record_processor_builder.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/instrumentationscope/scope_configurator.h" +#include "opentelemetry/sdk/logs/batch_log_record_processor_factory.h" +#include "opentelemetry/sdk/logs/batch_log_record_processor_options.h" +#include "opentelemetry/sdk/logs/logger_config.h" +#include "opentelemetry/sdk/logs/processor.h" +#include "opentelemetry/sdk/logs/simple_log_record_processor_factory.h" +#include "opentelemetry/version.h" +#include "src/common/wildcard_match.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +namespace +{ + +static opentelemetry::logs::Severity ToLogSeverity( + opentelemetry::sdk::configuration::SeverityNumber severity_number) +{ + switch (severity_number) + { + case SeverityNumber::trace: + return opentelemetry::logs::Severity::kTrace; + case SeverityNumber::trace2: + return opentelemetry::logs::Severity::kTrace2; + case SeverityNumber::trace3: + return opentelemetry::logs::Severity::kTrace3; + case SeverityNumber::trace4: + return opentelemetry::logs::Severity::kTrace4; + case SeverityNumber::debug: + return opentelemetry::logs::Severity::kDebug; + case SeverityNumber::debug2: + return opentelemetry::logs::Severity::kDebug2; + case SeverityNumber::debug3: + return opentelemetry::logs::Severity::kDebug3; + case SeverityNumber::debug4: + return opentelemetry::logs::Severity::kDebug4; + case SeverityNumber::info: + return opentelemetry::logs::Severity::kInfo; + case SeverityNumber::info2: + return opentelemetry::logs::Severity::kInfo2; + case SeverityNumber::info3: + return opentelemetry::logs::Severity::kInfo3; + case SeverityNumber::info4: + return opentelemetry::logs::Severity::kInfo4; + case SeverityNumber::warn: + return opentelemetry::logs::Severity::kWarn; + case SeverityNumber::warn2: + return opentelemetry::logs::Severity::kWarn2; + case SeverityNumber::warn3: + return opentelemetry::logs::Severity::kWarn3; + case SeverityNumber::warn4: + return opentelemetry::logs::Severity::kWarn4; + case SeverityNumber::error: + return opentelemetry::logs::Severity::kError; + case SeverityNumber::error2: + return opentelemetry::logs::Severity::kError2; + case SeverityNumber::error3: + return opentelemetry::logs::Severity::kError3; + case SeverityNumber::error4: + return opentelemetry::logs::Severity::kError4; + case SeverityNumber::fatal: + return opentelemetry::logs::Severity::kFatal; + case SeverityNumber::fatal2: + return opentelemetry::logs::Severity::kFatal2; + case SeverityNumber::fatal3: + return opentelemetry::logs::Severity::kFatal3; + case SeverityNumber::fatal4: + return opentelemetry::logs::Severity::kFatal4; + default: + break; + } + return opentelemetry::logs::Severity::kInvalid; +} + +class DefaultBatchLogRecordProcessorBuilder : public BatchLogRecordProcessorBuilder +{ +public: + std::unique_ptr Build( + const BatchLogRecordProcessorConfiguration *model, + std::unique_ptr &&exporter) const override + { + opentelemetry::sdk::logs::BatchLogRecordProcessorOptions options; + options.schedule_delay_millis = std::chrono::milliseconds(model->schedule_delay); + options.export_timeout_millis = std::chrono::milliseconds(model->export_timeout); + options.max_queue_size = model->max_queue_size; + options.max_export_batch_size = model->max_export_batch_size; + return opentelemetry::sdk::logs::BatchLogRecordProcessorFactory::Create(std::move(exporter), + options); + } +}; + +class DefaultSimpleLogRecordProcessorBuilder : public SimpleLogRecordProcessorBuilder +{ +public: + std::unique_ptr Build( + const SimpleLogRecordProcessorConfiguration * /* model */, + std::unique_ptr &&exporter) const override + { + return opentelemetry::sdk::logs::SimpleLogRecordProcessorFactory::Create(std::move(exporter)); + } +}; + +class DefaultLoggerConfiguratorBuilder : public LoggerConfiguratorBuilder +{ +public: + std::unique_ptr> + Build(const LoggerConfiguratorConfiguration *model) const override + { + using common::WildcardMatch; + using opentelemetry::sdk::instrumentationscope::InstrumentationScope; + using opentelemetry::sdk::instrumentationscope::ScopeConfigurator; + using opentelemetry::sdk::logs::LoggerConfig; + + LoggerConfig default_config = LoggerConfig::Create( + model->default_config.enabled, ToLogSeverity(model->default_config.minimum_severity), + model->default_config.trace_based); + auto builder = ScopeConfigurator::Builder(default_config); + + for (const auto &entry : model->loggers) + { + LoggerConfig entry_config = + LoggerConfig::Create(entry.config.enabled, ToLogSeverity(entry.config.minimum_severity), + entry.config.trace_based); + std::string pattern = entry.name; + builder.AddCondition( + [pattern](const InstrumentationScope &scope) { + return WildcardMatch(pattern, scope.GetName()); + }, + entry_config); + } + + return std::make_unique>(builder.Build()); + } +}; + +} // namespace + +void RegisterDefaultLogsBuilders(Registry *registry) +{ + registry->SetBatchLogRecordProcessorBuilder( + std::make_unique()); + registry->SetSimpleLogRecordProcessorBuilder( + std::make_unique()); + registry->SetLoggerConfiguratorBuilder(std::make_unique()); +} + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE From f3328f32651324b1b7135c2d95f8b85cfee0280a Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Wed, 5 Aug 2026 15:08:13 -0400 Subject: [PATCH 02/20] add sdk metrics component builders --- .../sdk/configuration/metrics_builders.h | 19 ++++ sdk/src/configuration/metrics_builders.cc | 97 +++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 sdk/include/opentelemetry/sdk/configuration/metrics_builders.h create mode 100644 sdk/src/configuration/metrics_builders.cc diff --git a/sdk/include/opentelemetry/sdk/configuration/metrics_builders.h b/sdk/include/opentelemetry/sdk/configuration/metrics_builders.h new file mode 100644 index 0000000000..bc34a51582 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/metrics_builders.h @@ -0,0 +1,19 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/registry.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +void RegisterDefaultMetricsBuilders(Registry *registry); + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/configuration/metrics_builders.cc b/sdk/src/configuration/metrics_builders.cc new file mode 100644 index 0000000000..00b4493628 --- /dev/null +++ b/sdk/src/configuration/metrics_builders.cc @@ -0,0 +1,97 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/sdk/configuration/metrics_builders.h" + +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/sdk/configuration/meter_config_configuration.h" +#include "opentelemetry/sdk/configuration/meter_configurator_builder.h" +#include "opentelemetry/sdk/configuration/meter_configurator_configuration.h" +#include "opentelemetry/sdk/configuration/meter_matcher_and_config_configuration.h" +#include "opentelemetry/sdk/configuration/periodic_metric_reader_builder.h" +#include "opentelemetry/sdk/configuration/periodic_metric_reader_configuration.h" +#include "opentelemetry/sdk/configuration/registry.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/instrumentationscope/scope_configurator.h" +#include "opentelemetry/sdk/metrics/export/metric_producer.h" +#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h" +#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h" +#include "opentelemetry/sdk/metrics/meter_config.h" +#include "opentelemetry/sdk/metrics/metric_reader.h" +#include "opentelemetry/sdk/metrics/push_metric_exporter.h" +#include "opentelemetry/version.h" +#include "src/common/wildcard_match.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +namespace +{ + +class DefaultPeriodicMetricReaderBuilder : public PeriodicMetricReaderBuilder +{ +public: + std::unique_ptr Build( + const PeriodicMetricReaderConfiguration *model, + std::unique_ptr &&exporter) const override + { + opentelemetry::sdk::metrics::PeriodicExportingMetricReaderOptions options; + options.export_interval_millis = std::chrono::milliseconds(model->interval); + options.export_timeout_millis = std::chrono::milliseconds(model->timeout); + return opentelemetry::sdk::metrics::PeriodicExportingMetricReaderFactory::Create( + std::move(exporter), options); + } +}; + +class DefaultMeterConfiguratorBuilder : public MeterConfiguratorBuilder +{ +public: + std::unique_ptr> + Build(const MeterConfiguratorConfiguration *model) const override + { + using common::WildcardMatch; + using opentelemetry::sdk::instrumentationscope::InstrumentationScope; + using opentelemetry::sdk::instrumentationscope::ScopeConfigurator; + using opentelemetry::sdk::metrics::MeterConfig; + + MeterConfig default_config = + model->default_config.enabled ? MeterConfig::Enabled() : MeterConfig::Disabled(); + auto builder = ScopeConfigurator::Builder(default_config); + + for (const auto &entry : model->meters) + { + MeterConfig entry_config = + entry.config.enabled ? MeterConfig::Enabled() : MeterConfig::Disabled(); + std::string pattern = entry.name; + builder.AddCondition( + [pattern](const InstrumentationScope &scope) { + return WildcardMatch(pattern, scope.GetName()); + }, + entry_config); + } + + return std::make_unique>(builder.Build()); + } +}; + +} // namespace + +void RegisterDefaultMetricsBuilders(Registry *registry) +{ + registry->SetPeriodicMetricReaderBuilder(std::make_unique()); + registry->SetMeterConfiguratorBuilder(std::make_unique()); +} + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE From 79770686e0ac03b516ead6ef38400b4eb3ef904a Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Wed, 5 Aug 2026 15:08:50 -0400 Subject: [PATCH 03/20] add sdk trace component builders --- .../sdk/configuration/trace_builders.h | 19 ++ sdk/src/configuration/trace_builders.cc | 284 ++++++++++++++++++ 2 files changed, 303 insertions(+) create mode 100644 sdk/include/opentelemetry/sdk/configuration/trace_builders.h create mode 100644 sdk/src/configuration/trace_builders.cc diff --git a/sdk/include/opentelemetry/sdk/configuration/trace_builders.h b/sdk/include/opentelemetry/sdk/configuration/trace_builders.h new file mode 100644 index 0000000000..02e7edf42c --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/trace_builders.h @@ -0,0 +1,19 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/sdk/configuration/registry.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +void RegisterDefaultTraceBuilders(Registry *registry); + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/configuration/trace_builders.cc b/sdk/src/configuration/trace_builders.cc new file mode 100644 index 0000000000..438b547972 --- /dev/null +++ b/sdk/src/configuration/trace_builders.cc @@ -0,0 +1,284 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/sdk/configuration/trace_builders.h" + +#include +#include +#include +#include +#include +#include + +#include "opentelemetry/sdk/configuration/always_off_sampler_builder.h" +#include "opentelemetry/sdk/configuration/always_on_sampler_builder.h" +#include "opentelemetry/sdk/configuration/batch_span_processor_builder.h" +#include "opentelemetry/sdk/configuration/batch_span_processor_configuration.h" +#include "opentelemetry/sdk/configuration/composable_always_off_sampler_builder.h" +#include "opentelemetry/sdk/configuration/composable_always_on_sampler_builder.h" +#include "opentelemetry/sdk/configuration/composable_parent_threshold_sampler_builder.h" +#include "opentelemetry/sdk/configuration/composable_probability_sampler_builder.h" +#include "opentelemetry/sdk/configuration/composable_probability_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/composable_rule_based_sampler_builder.h" +#include "opentelemetry/sdk/configuration/jaeger_remote_sampler_builder.h" +#include "opentelemetry/sdk/configuration/parent_based_sampler_builder.h" +#include "opentelemetry/sdk/configuration/probability_sampler_builder.h" +#include "opentelemetry/sdk/configuration/probability_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/registry.h" +#include "opentelemetry/sdk/configuration/simple_span_processor_builder.h" +#include "opentelemetry/sdk/configuration/trace_id_ratio_based_sampler_builder.h" +#include "opentelemetry/sdk/configuration/trace_id_ratio_based_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/tracer_config_configuration.h" +#include "opentelemetry/sdk/configuration/tracer_configurator_builder.h" +#include "opentelemetry/sdk/configuration/tracer_configurator_configuration.h" +#include "opentelemetry/sdk/configuration/tracer_matcher_and_config_configuration.h" +#include "opentelemetry/sdk/configuration/unsupported_exception.h" +#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" +#include "opentelemetry/sdk/instrumentationscope/scope_configurator.h" +#include "opentelemetry/sdk/trace/batch_span_processor_factory.h" +#include "opentelemetry/sdk/trace/batch_span_processor_options.h" +#include "opentelemetry/sdk/trace/processor.h" +#include "opentelemetry/sdk/trace/sampler.h" +#include "opentelemetry/sdk/trace/samplers/always_off_factory.h" +#include "opentelemetry/sdk/trace/samplers/always_on_factory.h" +#include "opentelemetry/sdk/trace/samplers/composable_always_off.h" +#include "opentelemetry/sdk/trace/samplers/composable_always_on.h" +#include "opentelemetry/sdk/trace/samplers/composable_parent_threshold.h" +#include "opentelemetry/sdk/trace/samplers/composable_probability.h" +#include "opentelemetry/sdk/trace/samplers/composable_sampler.h" +#include "opentelemetry/sdk/trace/samplers/parent_factory.h" +#include "opentelemetry/sdk/trace/samplers/probability_factory.h" +#include "opentelemetry/sdk/trace/samplers/trace_id_ratio_factory.h" +#include "opentelemetry/sdk/trace/simple_processor_factory.h" +#include "opentelemetry/sdk/trace/tracer_config.h" +#include "opentelemetry/version.h" +#include "src/common/wildcard_match.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +namespace +{ + +class DefaultAlwaysOnSamplerBuilder : public AlwaysOnSamplerBuilder +{ +public: + std::unique_ptr Build( + const AlwaysOnSamplerConfiguration * /* model */) const override + { + return opentelemetry::sdk::trace::AlwaysOnSamplerFactory::Create(); + } +}; + +class DefaultAlwaysOffSamplerBuilder : public AlwaysOffSamplerBuilder +{ +public: + std::unique_ptr Build( + const AlwaysOffSamplerConfiguration * /* model */) const override + { + return opentelemetry::sdk::trace::AlwaysOffSamplerFactory::Create(); + } +}; + +class DefaultTraceIdRatioBasedSamplerBuilder : public TraceIdRatioBasedSamplerBuilder +{ +public: + std::unique_ptr Build( + const TraceIdRatioBasedSamplerConfiguration *model) const override + { + return opentelemetry::sdk::trace::TraceIdRatioBasedSamplerFactory::Create(model->ratio); + } +}; + +class DefaultProbabilitySamplerBuilder : public ProbabilitySamplerBuilder +{ +public: + std::unique_ptr Build( + const ProbabilitySamplerConfiguration *model) const override + { + return opentelemetry::sdk::trace::ProbabilitySamplerFactory::Create(model->ratio); + } +}; + +class DefaultParentBasedSamplerBuilder : public ParentBasedSamplerBuilder +{ +public: + std::unique_ptr Build( + const ParentBasedSamplerConfiguration * /* model */, + std::unique_ptr &&root, + std::unique_ptr &&remote_parent_sampled, + std::unique_ptr &&remote_parent_not_sampled, + std::unique_ptr &&local_parent_sampled, + std::unique_ptr &&local_parent_not_sampled) const override + { + return opentelemetry::sdk::trace::ParentBasedSamplerFactory::Create( + std::shared_ptr(std::move(root)), + std::shared_ptr(std::move(remote_parent_sampled)), + std::shared_ptr(std::move(remote_parent_not_sampled)), + std::shared_ptr(std::move(local_parent_sampled)), + std::shared_ptr(std::move(local_parent_not_sampled))); + } +}; + +class DefaultJaegerRemoteSamplerBuilder : public JaegerRemoteSamplerBuilder +{ +public: + std::unique_ptr Build( + const JaegerRemoteSamplerConfiguration * /* model */, + std::unique_ptr && /* initial_sampler */) const override + { + static const std::string die("JaegerRemoteSampler not supported"); + throw UnsupportedException(die); + } +}; + +class DefaultBatchSpanProcessorBuilder : public BatchSpanProcessorBuilder +{ +public: + std::unique_ptr Build( + const BatchSpanProcessorConfiguration *model, + std::unique_ptr &&exporter) const override + { + opentelemetry::sdk::trace::BatchSpanProcessorOptions options; + options.schedule_delay_millis = std::chrono::milliseconds(model->schedule_delay); + options.export_timeout = std::chrono::milliseconds(model->export_timeout); + options.max_queue_size = model->max_queue_size; + options.max_export_batch_size = model->max_export_batch_size; + return opentelemetry::sdk::trace::BatchSpanProcessorFactory::Create(std::move(exporter), + options); + } +}; + +class DefaultSimpleSpanProcessorBuilder : public SimpleSpanProcessorBuilder +{ +public: + std::unique_ptr Build( + const SimpleSpanProcessorConfiguration * /* model */, + std::unique_ptr &&exporter) const override + { + return opentelemetry::sdk::trace::SimpleSpanProcessorFactory::Create(std::move(exporter)); + } +}; + +class DefaultComposableAlwaysOnSamplerBuilder : public ComposableAlwaysOnSamplerBuilder +{ +public: + std::unique_ptr Build( + const ComposableAlwaysOnSamplerConfiguration * /* model */) const override + { + return std::make_unique(); + } +}; + +class DefaultComposableAlwaysOffSamplerBuilder : public ComposableAlwaysOffSamplerBuilder +{ +public: + std::unique_ptr Build( + const ComposableAlwaysOffSamplerConfiguration * /* model */) const override + { + return std::make_unique(); + } +}; + +class DefaultComposableProbabilitySamplerBuilder : public ComposableProbabilitySamplerBuilder +{ +public: + std::unique_ptr Build( + const ComposableProbabilitySamplerConfiguration *model) const override + { + double ratio = model ? model->ratio : ComposableProbabilitySamplerConfiguration::kDefaultRatio; + return std::make_unique(ratio); + } +}; + +class DefaultComposableParentThresholdSamplerBuilder + : public ComposableParentThresholdSamplerBuilder +{ +public: + std::unique_ptr Build( + const ComposableParentThresholdSamplerConfiguration * /* model */, + std::unique_ptr &&root) const override + { + return std::make_unique( + std::shared_ptr(std::move(root))); + } +}; + +class DefaultComposableRuleBasedSamplerBuilder : public ComposableRuleBasedSamplerBuilder +{ +public: + std::unique_ptr Build( + const ComposableRuleBasedSamplerConfiguration * /* model */, + std::vector> + && /* rule_samplers */) const override + { + // TODO: implement once a concrete Predicate can be built from rule config + static const std::string die("ComposableRuleBasedSampler not supported"); + throw UnsupportedException(die); + } +}; + +class DefaultTracerConfiguratorBuilder : public TracerConfiguratorBuilder +{ +public: + std::unique_ptr> + Build(const TracerConfiguratorConfiguration *model) const override + { + using common::WildcardMatch; + using opentelemetry::sdk::instrumentationscope::InstrumentationScope; + using opentelemetry::sdk::instrumentationscope::ScopeConfigurator; + using opentelemetry::sdk::trace::TracerConfig; + + TracerConfig default_config = + model->default_config.enabled ? TracerConfig::Enabled() : TracerConfig::Disabled(); + auto builder = ScopeConfigurator::Builder(default_config); + + for (const auto &entry : model->tracers) + { + TracerConfig entry_config = + entry.config.enabled ? TracerConfig::Enabled() : TracerConfig::Disabled(); + std::string pattern = entry.name; + builder.AddCondition( + [pattern](const InstrumentationScope &scope) { + return WildcardMatch(pattern, scope.GetName()); + }, + entry_config); + } + + return std::make_unique>(builder.Build()); + } +}; + +} // namespace + +void RegisterDefaultTraceBuilders(Registry *registry) +{ + registry->SetAlwaysOnSamplerBuilder(std::make_unique()); + registry->SetAlwaysOffSamplerBuilder(std::make_unique()); + registry->SetTraceIdRatioBasedSamplerBuilder( + std::make_unique()); + registry->SetProbabilitySamplerBuilder(std::make_unique()); + registry->SetParentBasedSamplerBuilder(std::make_unique()); + registry->SetJaegerRemoteSamplerBuilder(std::make_unique()); + registry->SetBatchSpanProcessorBuilder(std::make_unique()); + registry->SetSimpleSpanProcessorBuilder(std::make_unique()); + registry->SetTracerConfiguratorBuilder(std::make_unique()); + registry->SetComposableAlwaysOnSamplerBuilder( + std::make_unique()); + registry->SetComposableAlwaysOffSamplerBuilder( + std::make_unique()); + registry->SetComposableProbabilitySamplerBuilder( + std::make_unique()); + registry->SetComposableParentThresholdSamplerBuilder( + std::make_unique()); + registry->SetComposableRuleBasedSamplerBuilder( + std::make_unique()); +} + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE From 98345ed8212d3f182e07e47ef80377348bf67edc Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Wed, 5 Aug 2026 15:10:32 -0400 Subject: [PATCH 04/20] update registry test --- sdk/src/configuration/registry.cc | 25 ------------------------- sdk/test/configuration/registry_test.cc | 16 +++------------- 2 files changed, 3 insertions(+), 38 deletions(-) diff --git a/sdk/src/configuration/registry.cc b/sdk/src/configuration/registry.cc index 16ced18754..53b37951cd 100644 --- a/sdk/src/configuration/registry.cc +++ b/sdk/src/configuration/registry.cc @@ -1,7 +1,6 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include #include #include #include @@ -47,7 +46,6 @@ #include "opentelemetry/sdk/configuration/otlp_http_span_exporter_builder.h" #include "opentelemetry/sdk/configuration/parent_based_sampler_builder.h" #include "opentelemetry/sdk/configuration/periodic_metric_reader_builder.h" -#include "opentelemetry/sdk/configuration/periodic_metric_reader_configuration.h" #include "opentelemetry/sdk/configuration/probability_sampler_builder.h" #include "opentelemetry/sdk/configuration/process_resource_detector_builder.h" #include "opentelemetry/sdk/configuration/prometheus_pull_metric_exporter_builder.h" @@ -59,10 +57,6 @@ #include "opentelemetry/sdk/configuration/text_map_propagator_builder.h" #include "opentelemetry/sdk/configuration/trace_id_ratio_based_sampler_builder.h" #include "opentelemetry/sdk/configuration/tracer_configurator_builder.h" -#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h" -#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h" -#include "opentelemetry/sdk/metrics/metric_reader.h" -#include "opentelemetry/sdk/metrics/push_metric_exporter.h" #include "opentelemetry/trace/propagation/b3_propagator.h" #include "opentelemetry/trace/propagation/http_trace_context.h" #include "opentelemetry/trace/propagation/jaeger.h" @@ -127,23 +121,6 @@ class JaegerBuilder : public TextMapPropagatorBuilder } }; -class DefaultPeriodicMetricReaderBuilder : public PeriodicMetricReaderBuilder -{ -public: - std::unique_ptr Build( - const opentelemetry::sdk::configuration::PeriodicMetricReaderConfiguration *model, - std::unique_ptr &&exporter) const override - { - opentelemetry::sdk::metrics::PeriodicExportingMetricReaderOptions options; - - options.export_interval_millis = std::chrono::milliseconds(model->interval); - options.export_timeout_millis = std::chrono::milliseconds(model->timeout); - - return opentelemetry::sdk::metrics::PeriodicExportingMetricReaderFactory::Create( - std::move(exporter), options); - } -}; - } // namespace Registry::Registry() @@ -153,8 +130,6 @@ Registry::Registry() SetTextMapPropagatorBuilder("b3", std::make_unique()); SetTextMapPropagatorBuilder("b3multi", std::make_unique()); SetTextMapPropagatorBuilder("jaeger", std::make_unique()); - - SetPeriodicMetricReaderBuilder(std::make_unique()); } Registry::~Registry() = default; diff --git a/sdk/test/configuration/registry_test.cc b/sdk/test/configuration/registry_test.cc index e77540b867..d44b4d7eb7 100644 --- a/sdk/test/configuration/registry_test.cc +++ b/sdk/test/configuration/registry_test.cc @@ -913,19 +913,9 @@ TEST(Registry, OtlpFileLogRecordBuilder) TEST(Registry, PeriodicMetricReaderBuilder) { - // Registry pre-populates this slot; test replace lifecycle only. - configuration::Registry registry; - ASSERT_NE(registry.GetPeriodicMetricReaderBuilder(), nullptr); - - auto first = std::make_unique(); - const auto *first_ptr = first.get(); - registry.SetPeriodicMetricReaderBuilder(std::move(first)); - ASSERT_EQ(registry.GetPeriodicMetricReaderBuilder(), first_ptr); - - auto second = std::make_unique(); - const auto *second_ptr = second.get(); - registry.SetPeriodicMetricReaderBuilder(std::move(second)); - ASSERT_EQ(registry.GetPeriodicMetricReaderBuilder(), second_ptr); + TestTypedSlot( + &configuration::Registry::GetPeriodicMetricReaderBuilder, + &configuration::Registry::SetPeriodicMetricReaderBuilder); } TEST(Registry, PrometheusPullMetricExporterBuilder) From 3c1ba5a783695c246de94d43b881ca6e1611035c Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Wed, 5 Aug 2026 15:11:22 -0400 Subject: [PATCH 05/20] use sdk default builders in SdkBuilder --- sdk/src/configuration/sdk_builder.cc | 399 ++++++++++----------------- 1 file changed, 151 insertions(+), 248 deletions(-) diff --git a/sdk/src/configuration/sdk_builder.cc b/sdk/src/configuration/sdk_builder.cc index ab8a2f4ed8..cddb13cc75 100644 --- a/sdk/src/configuration/sdk_builder.cc +++ b/sdk/src/configuration/sdk_builder.cc @@ -1,10 +1,8 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -#include #include #include -#include #include #include #include @@ -16,19 +14,22 @@ #include "opentelemetry/common/kv_properties.h" #include "opentelemetry/context/propagation/composite_propagator.h" #include "opentelemetry/context/propagation/text_map_propagator.h" -#include "opentelemetry/logs/severity.h" #include "opentelemetry/nostd/span.h" #include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/common/global_log_handler.h" #include "opentelemetry/sdk/configuration/aggregation_configuration.h" #include "opentelemetry/sdk/configuration/aggregation_configuration_visitor.h" +#include "opentelemetry/sdk/configuration/always_off_sampler_builder.h" #include "opentelemetry/sdk/configuration/always_off_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/always_on_sampler_builder.h" #include "opentelemetry/sdk/configuration/always_on_sampler_configuration.h" #include "opentelemetry/sdk/configuration/attribute_value_configuration.h" #include "opentelemetry/sdk/configuration/attribute_value_configuration_visitor.h" #include "opentelemetry/sdk/configuration/attributes_configuration.h" #include "opentelemetry/sdk/configuration/base2_exponential_bucket_histogram_aggregation_configuration.h" +#include "opentelemetry/sdk/configuration/batch_log_record_processor_builder.h" #include "opentelemetry/sdk/configuration/batch_log_record_processor_configuration.h" +#include "opentelemetry/sdk/configuration/batch_span_processor_builder.h" #include "opentelemetry/sdk/configuration/batch_span_processor_configuration.h" #include "opentelemetry/sdk/configuration/boolean_array_attribute_value_configuration.h" #include "opentelemetry/sdk/configuration/boolean_attribute_value_configuration.h" @@ -64,19 +65,18 @@ #include "opentelemetry/sdk/configuration/instrument_type.h" #include "opentelemetry/sdk/configuration/integer_array_attribute_value_configuration.h" #include "opentelemetry/sdk/configuration/integer_attribute_value_configuration.h" +#include "opentelemetry/sdk/configuration/jaeger_remote_sampler_builder.h" #include "opentelemetry/sdk/configuration/jaeger_remote_sampler_configuration.h" #include "opentelemetry/sdk/configuration/log_record_exporter_configuration.h" #include "opentelemetry/sdk/configuration/log_record_exporter_configuration_visitor.h" #include "opentelemetry/sdk/configuration/log_record_limits_configuration.h" #include "opentelemetry/sdk/configuration/log_record_processor_configuration.h" #include "opentelemetry/sdk/configuration/log_record_processor_configuration_visitor.h" -#include "opentelemetry/sdk/configuration/logger_config_configuration.h" +#include "opentelemetry/sdk/configuration/logger_configurator_builder.h" #include "opentelemetry/sdk/configuration/logger_configurator_configuration.h" -#include "opentelemetry/sdk/configuration/logger_matcher_and_config_configuration.h" #include "opentelemetry/sdk/configuration/logger_provider_configuration.h" -#include "opentelemetry/sdk/configuration/meter_config_configuration.h" +#include "opentelemetry/sdk/configuration/meter_configurator_builder.h" #include "opentelemetry/sdk/configuration/meter_configurator_configuration.h" -#include "opentelemetry/sdk/configuration/meter_matcher_and_config_configuration.h" #include "opentelemetry/sdk/configuration/meter_provider_configuration.h" #include "opentelemetry/sdk/configuration/metric_reader_configuration.h" #include "opentelemetry/sdk/configuration/metric_reader_configuration_visitor.h" @@ -98,9 +98,11 @@ #include "opentelemetry/sdk/configuration/otlp_http_push_metric_exporter_configuration.h" #include "opentelemetry/sdk/configuration/otlp_http_span_exporter_builder.h" #include "opentelemetry/sdk/configuration/otlp_http_span_exporter_configuration.h" +#include "opentelemetry/sdk/configuration/parent_based_sampler_builder.h" #include "opentelemetry/sdk/configuration/parent_based_sampler_configuration.h" #include "opentelemetry/sdk/configuration/periodic_metric_reader_builder.h" #include "opentelemetry/sdk/configuration/periodic_metric_reader_configuration.h" +#include "opentelemetry/sdk/configuration/probability_sampler_builder.h" #include "opentelemetry/sdk/configuration/probability_sampler_configuration.h" #include "opentelemetry/sdk/configuration/prometheus_pull_metric_exporter_builder.h" #include "opentelemetry/sdk/configuration/prometheus_pull_metric_exporter_configuration.h" @@ -116,7 +118,9 @@ #include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" #include "opentelemetry/sdk/configuration/sdk_builder.h" #include "opentelemetry/sdk/configuration/severity_number.h" +#include "opentelemetry/sdk/configuration/simple_log_record_processor_builder.h" #include "opentelemetry/sdk/configuration/simple_log_record_processor_configuration.h" +#include "opentelemetry/sdk/configuration/simple_span_processor_builder.h" #include "opentelemetry/sdk/configuration/simple_span_processor_configuration.h" #include "opentelemetry/sdk/configuration/span_exporter_configuration.h" #include "opentelemetry/sdk/configuration/span_exporter_configuration_visitor.h" @@ -126,27 +130,22 @@ #include "opentelemetry/sdk/configuration/string_array_attribute_value_configuration.h" #include "opentelemetry/sdk/configuration/string_attribute_value_configuration.h" #include "opentelemetry/sdk/configuration/text_map_propagator_builder.h" +#include "opentelemetry/sdk/configuration/trace_id_ratio_based_sampler_builder.h" #include "opentelemetry/sdk/configuration/trace_id_ratio_based_sampler_configuration.h" -#include "opentelemetry/sdk/configuration/tracer_config_configuration.h" +#include "opentelemetry/sdk/configuration/tracer_configurator_builder.h" #include "opentelemetry/sdk/configuration/tracer_configurator_configuration.h" -#include "opentelemetry/sdk/configuration/tracer_matcher_and_config_configuration.h" #include "opentelemetry/sdk/configuration/tracer_provider_configuration.h" #include "opentelemetry/sdk/configuration/unsupported_exception.h" #include "opentelemetry/sdk/configuration/view_configuration.h" #include "opentelemetry/sdk/configuration/view_selector_configuration.h" #include "opentelemetry/sdk/configuration/view_stream_configuration.h" -#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h" #include "opentelemetry/sdk/instrumentationscope/scope_configurator.h" -#include "opentelemetry/sdk/logs/batch_log_record_processor_factory.h" -#include "opentelemetry/sdk/logs/batch_log_record_processor_options.h" #include "opentelemetry/sdk/logs/exporter.h" #include "opentelemetry/sdk/logs/log_record_limits.h" #include "opentelemetry/sdk/logs/logger_config.h" #include "opentelemetry/sdk/logs/logger_provider.h" #include "opentelemetry/sdk/logs/logger_provider_factory.h" #include "opentelemetry/sdk/logs/processor.h" -#include "opentelemetry/sdk/logs/recordable.h" -#include "opentelemetry/sdk/logs/simple_log_record_processor_factory.h" #include "opentelemetry/sdk/metrics/aggregation/aggregation_config.h" #include "opentelemetry/sdk/metrics/aggregation/default_aggregation.h" #include "opentelemetry/sdk/metrics/cardinality_limits.h" @@ -165,19 +164,11 @@ #include "opentelemetry/sdk/metrics/view/view_registry.h" #include "opentelemetry/sdk/metrics/view/view_registry_factory.h" #include "opentelemetry/sdk/resource/resource.h" -#include "opentelemetry/sdk/trace/batch_span_processor_factory.h" -#include "opentelemetry/sdk/trace/batch_span_processor_options.h" #include "opentelemetry/sdk/trace/exporter.h" #include "opentelemetry/sdk/trace/id_generator.h" #include "opentelemetry/sdk/trace/processor.h" #include "opentelemetry/sdk/trace/random_id_generator_factory.h" #include "opentelemetry/sdk/trace/sampler.h" -#include "opentelemetry/sdk/trace/samplers/always_off_factory.h" -#include "opentelemetry/sdk/trace/samplers/always_on_factory.h" -#include "opentelemetry/sdk/trace/samplers/parent_factory.h" -#include "opentelemetry/sdk/trace/samplers/probability_factory.h" -#include "opentelemetry/sdk/trace/samplers/trace_id_ratio_factory.h" -#include "opentelemetry/sdk/trace/simple_processor_factory.h" #include "opentelemetry/sdk/trace/span_limits.h" #include "opentelemetry/sdk/trace/tracer_config.h" #include "opentelemetry/sdk/trace/tracer_provider.h" @@ -200,68 +191,6 @@ using common::WildcardMatch; namespace { -static opentelemetry::logs::Severity ToLogSeverity( - opentelemetry::sdk::configuration::SeverityNumber severity_number) -{ - // Convert configuration::SeverityNumber to opentelemetry::logs::Severity - // The configuration::SeverityNumber enum values do not match the opentelemetry::logs::Severity - // enum values use a switch statement for conversion. - switch (severity_number) - { - case SeverityNumber::trace: - return opentelemetry::logs::Severity::kTrace; - case SeverityNumber::trace2: - return opentelemetry::logs::Severity::kTrace2; - case SeverityNumber::trace3: - return opentelemetry::logs::Severity::kTrace3; - case SeverityNumber::trace4: - return opentelemetry::logs::Severity::kTrace4; - case SeverityNumber::debug: - return opentelemetry::logs::Severity::kDebug; - case SeverityNumber::debug2: - return opentelemetry::logs::Severity::kDebug2; - case SeverityNumber::debug3: - return opentelemetry::logs::Severity::kDebug3; - case SeverityNumber::debug4: - return opentelemetry::logs::Severity::kDebug4; - case SeverityNumber::info: - return opentelemetry::logs::Severity::kInfo; - case SeverityNumber::info2: - return opentelemetry::logs::Severity::kInfo2; - case SeverityNumber::info3: - return opentelemetry::logs::Severity::kInfo3; - case SeverityNumber::info4: - return opentelemetry::logs::Severity::kInfo4; - case SeverityNumber::warn: - return opentelemetry::logs::Severity::kWarn; - case SeverityNumber::warn2: - return opentelemetry::logs::Severity::kWarn2; - case SeverityNumber::warn3: - return opentelemetry::logs::Severity::kWarn3; - case SeverityNumber::warn4: - return opentelemetry::logs::Severity::kWarn4; - case SeverityNumber::error: - return opentelemetry::logs::Severity::kError; - case SeverityNumber::error2: - return opentelemetry::logs::Severity::kError2; - case SeverityNumber::error3: - return opentelemetry::logs::Severity::kError3; - case SeverityNumber::error4: - return opentelemetry::logs::Severity::kError4; - case SeverityNumber::fatal: - return opentelemetry::logs::Severity::kFatal; - case SeverityNumber::fatal2: - return opentelemetry::logs::Severity::kFatal2; - case SeverityNumber::fatal3: - return opentelemetry::logs::Severity::kFatal3; - case SeverityNumber::fatal4: - return opentelemetry::logs::Severity::kFatal4; - default: - break; - } - return opentelemetry::logs::Severity::kInvalid; -} - /// Convert a CardinalityLimitsConfiguration (where 0 means "unset, use /// default_limit") into a fully-resolved CardinalityLimits struct ready for /// MetricReader::SetCardinalityLimits(). @@ -485,21 +414,25 @@ class SamplerBuilder : public opentelemetry::sdk::configuration::SamplerConfigur const opentelemetry::sdk::configuration::ComposableAlwaysOffSamplerConfiguration * /* model */) override { - sampler = opentelemetry::sdk::trace::AlwaysOffSamplerFactory::Create(); + static const opentelemetry::sdk::configuration::AlwaysOffSamplerConfiguration kAlwaysOff; + sampler = sdk_builder_->CreateAlwaysOffSampler(&kAlwaysOff); } void VisitComposableAlwaysOn( const opentelemetry::sdk::configuration::ComposableAlwaysOnSamplerConfiguration * /* model */) override { - sampler = opentelemetry::sdk::trace::AlwaysOnSamplerFactory::Create(); + static const opentelemetry::sdk::configuration::AlwaysOnSamplerConfiguration kAlwaysOn; + sampler = sdk_builder_->CreateAlwaysOnSampler(&kAlwaysOn); } void VisitComposableProbability( const opentelemetry::sdk::configuration::ComposableProbabilitySamplerConfiguration *model) override { - sampler = opentelemetry::sdk::trace::TraceIdRatioBasedSamplerFactory::Create(model->ratio); + opentelemetry::sdk::configuration::TraceIdRatioBasedSamplerConfiguration cfg; + cfg.ratio = model->ratio; + sampler = sdk_builder_->CreateTraceIdRatioBasedSampler(&cfg); } void VisitComposableParentThreshold( @@ -508,7 +441,8 @@ class SamplerBuilder : public opentelemetry::sdk::configuration::SamplerConfigur { // FIXME-SDK: https://github.com/open-telemetry/opentelemetry-cpp/issues/4028 OTEL_INTERNAL_LOG_WARN("ComposableParentThresholdSampler not yet fully supported by SDK"); - sampler = opentelemetry::sdk::trace::AlwaysOnSamplerFactory::Create(); + static const opentelemetry::sdk::configuration::AlwaysOnSamplerConfiguration kAlwaysOn; + sampler = sdk_builder_->CreateAlwaysOnSampler(&kAlwaysOn); } void VisitComposableRuleBased( @@ -517,7 +451,8 @@ class SamplerBuilder : public opentelemetry::sdk::configuration::SamplerConfigur { // FIXME-SDK: https://github.com/open-telemetry/opentelemetry-cpp/issues/4028 OTEL_INTERNAL_LOG_WARN("ComposableRuleBasedSampler not yet fully supported by SDK"); - sampler = opentelemetry::sdk::trace::AlwaysOnSamplerFactory::Create(); + static const opentelemetry::sdk::configuration::AlwaysOnSamplerConfiguration kAlwaysOn; + sampler = sdk_builder_->CreateAlwaysOnSampler(&kAlwaysOn); } std::unique_ptr sampler; @@ -865,29 +800,43 @@ class LogRecordExporterBuilder } // namespace std::unique_ptr SdkBuilder::CreateAlwaysOffSampler( - const opentelemetry::sdk::configuration::AlwaysOffSamplerConfiguration * /* model */) const + const opentelemetry::sdk::configuration::AlwaysOffSamplerConfiguration *model) const { - std::unique_ptr sdk; - - sdk = opentelemetry::sdk::trace::AlwaysOffSamplerFactory::Create(); - - return sdk; + const AlwaysOffSamplerBuilder *builder = registry_->GetAlwaysOffSamplerBuilder(); + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateAlwaysOffSampler() using registered builder"); + return builder->Build(model); + } + static const std::string die("No builder for AlwaysOffSampler"); + throw UnsupportedException(die); } std::unique_ptr SdkBuilder::CreateAlwaysOnSampler( - const opentelemetry::sdk::configuration::AlwaysOnSamplerConfiguration * /* model */) const + const opentelemetry::sdk::configuration::AlwaysOnSamplerConfiguration *model) const { - std::unique_ptr sdk; - - sdk = opentelemetry::sdk::trace::AlwaysOnSamplerFactory::Create(); - - return sdk; + const AlwaysOnSamplerBuilder *builder = registry_->GetAlwaysOnSamplerBuilder(); + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateAlwaysOnSampler() using registered builder"); + return builder->Build(model); + } + static const std::string die("No builder for AlwaysOnSampler"); + throw UnsupportedException(die); } std::unique_ptr SdkBuilder::CreateJaegerRemoteSampler( - const opentelemetry::sdk::configuration::JaegerRemoteSamplerConfiguration * /* model */) const + const opentelemetry::sdk::configuration::JaegerRemoteSamplerConfiguration *model) const { - static const std::string die("JaegerRemoteSampler not supported"); + const JaegerRemoteSamplerBuilder *builder = registry_->GetJaegerRemoteSamplerBuilder(); + if (builder != nullptr) + { + static const opentelemetry::sdk::configuration::AlwaysOnSamplerConfiguration kAlwaysOn; + auto initial_sampler = CreateAlwaysOnSampler(&kAlwaysOn); + OTEL_INTERNAL_LOG_DEBUG("CreateJaegerRemoteSampler() using registered builder"); + return builder->Build(model, std::move(initial_sampler)); + } + static const std::string die("No builder for JaegerRemoteSampler"); throw UnsupportedException(die); } @@ -907,7 +856,8 @@ std::unique_ptr SdkBuilder::CreateParentBase } else { - root_sdk = opentelemetry::sdk::trace::AlwaysOnSamplerFactory::Create(); + static const opentelemetry::sdk::configuration::AlwaysOnSamplerConfiguration kAlwaysOn; + root_sdk = CreateAlwaysOnSampler(&kAlwaysOn); } if (model->remote_parent_sampled != nullptr) @@ -916,7 +866,8 @@ std::unique_ptr SdkBuilder::CreateParentBase } else { - remote_parent_sampled_sdk = opentelemetry::sdk::trace::AlwaysOnSamplerFactory::Create(); + static const opentelemetry::sdk::configuration::AlwaysOnSamplerConfiguration kAlwaysOn; + remote_parent_sampled_sdk = CreateAlwaysOnSampler(&kAlwaysOn); } if (model->remote_parent_not_sampled != nullptr) @@ -925,7 +876,8 @@ std::unique_ptr SdkBuilder::CreateParentBase } else { - remote_parent_not_sampled_sdk = opentelemetry::sdk::trace::AlwaysOffSamplerFactory::Create(); + static const opentelemetry::sdk::configuration::AlwaysOffSamplerConfiguration kAlwaysOff; + remote_parent_not_sampled_sdk = CreateAlwaysOffSampler(&kAlwaysOff); } if (model->local_parent_sampled != nullptr) @@ -934,7 +886,8 @@ std::unique_ptr SdkBuilder::CreateParentBase } else { - local_parent_sampled_sdk = opentelemetry::sdk::trace::AlwaysOnSamplerFactory::Create(); + static const opentelemetry::sdk::configuration::AlwaysOnSamplerConfiguration kAlwaysOn; + local_parent_sampled_sdk = CreateAlwaysOnSampler(&kAlwaysOn); } if (model->local_parent_not_sampled != nullptr) @@ -943,44 +896,47 @@ std::unique_ptr SdkBuilder::CreateParentBase } else { - local_parent_not_sampled_sdk = opentelemetry::sdk::trace::AlwaysOffSamplerFactory::Create(); + static const opentelemetry::sdk::configuration::AlwaysOffSamplerConfiguration kAlwaysOff; + local_parent_not_sampled_sdk = CreateAlwaysOffSampler(&kAlwaysOff); } - std::shared_ptr shared_root = std::move(root_sdk); - std::shared_ptr shared_remote_parent_sampled = - std::move(remote_parent_sampled_sdk); - std::shared_ptr shared_remote_parent_not_sampled = - std::move(remote_parent_not_sampled_sdk); - std::shared_ptr shared_local_parent_sampled = - std::move(local_parent_sampled_sdk); - std::shared_ptr shared_local_parent_not_sampled = - std::move(local_parent_not_sampled_sdk); - - sdk = opentelemetry::sdk::trace::ParentBasedSamplerFactory::Create( - shared_root, shared_remote_parent_sampled, shared_remote_parent_not_sampled, - shared_local_parent_sampled, shared_local_parent_not_sampled); - - return sdk; + const ParentBasedSamplerBuilder *builder = registry_->GetParentBasedSamplerBuilder(); + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateParentBasedSampler() using registered builder"); + return builder->Build(model, std::move(root_sdk), std::move(remote_parent_sampled_sdk), + std::move(remote_parent_not_sampled_sdk), + std::move(local_parent_sampled_sdk), + std::move(local_parent_not_sampled_sdk)); + } + static const std::string die("No builder for ParentBasedSampler"); + throw UnsupportedException(die); } std::unique_ptr SdkBuilder::CreateProbabilitySampler( const opentelemetry::sdk::configuration::ProbabilitySamplerConfiguration *model) const { - std::unique_ptr sdk; - - sdk = opentelemetry::sdk::trace::ProbabilitySamplerFactory::Create(model->ratio); - - return sdk; + const ProbabilitySamplerBuilder *builder = registry_->GetProbabilitySamplerBuilder(); + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateProbabilitySampler() using registered builder"); + return builder->Build(model); + } + static const std::string die("No builder for ProbabilitySampler"); + throw UnsupportedException(die); } std::unique_ptr SdkBuilder::CreateTraceIdRatioBasedSampler( const opentelemetry::sdk::configuration::TraceIdRatioBasedSamplerConfiguration *model) const { - std::unique_ptr sdk; - - sdk = opentelemetry::sdk::trace::TraceIdRatioBasedSamplerFactory::Create(model->ratio); - - return sdk; + const TraceIdRatioBasedSamplerBuilder *builder = registry_->GetTraceIdRatioBasedSamplerBuilder(); + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateTraceIdRatioBasedSampler() using registered builder"); + return builder->Build(model); + } + static const std::string die("No builder for TraceIdRatioBasedSampler"); + throw UnsupportedException(die); } std::unique_ptr SdkBuilder::CreateExtensionSampler( @@ -1116,31 +1072,31 @@ std::unique_ptr SdkBuilder::CreateSpanE std::unique_ptr SdkBuilder::CreateBatchSpanProcessor( const opentelemetry::sdk::configuration::BatchSpanProcessorConfiguration *model) const { - std::unique_ptr sdk; - opentelemetry::sdk::trace::BatchSpanProcessorOptions options; - - options.schedule_delay_millis = std::chrono::milliseconds(model->schedule_delay); - options.export_timeout = std::chrono::milliseconds(model->export_timeout); - options.max_queue_size = model->max_queue_size; - options.max_export_batch_size = model->max_export_batch_size; - auto exporter_sdk = CreateSpanExporter(model->exporter); - sdk = opentelemetry::sdk::trace::BatchSpanProcessorFactory::Create(std::move(exporter_sdk), - options); - return sdk; + const BatchSpanProcessorBuilder *builder = registry_->GetBatchSpanProcessorBuilder(); + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateBatchSpanProcessor() using registered builder"); + return builder->Build(model, std::move(exporter_sdk)); + } + static const std::string die("No builder for BatchSpanProcessor"); + throw UnsupportedException(die); } std::unique_ptr SdkBuilder::CreateSimpleSpanProcessor( const opentelemetry::sdk::configuration::SimpleSpanProcessorConfiguration *model) const { - std::unique_ptr sdk; - auto exporter_sdk = CreateSpanExporter(model->exporter); - sdk = opentelemetry::sdk::trace::SimpleSpanProcessorFactory::Create(std::move(exporter_sdk)); - - return sdk; + const SimpleSpanProcessorBuilder *builder = registry_->GetSimpleSpanProcessorBuilder(); + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateSimpleSpanProcessor() using registered builder"); + return builder->Build(model, std::move(exporter_sdk)); + } + static const std::string die("No builder for SimpleSpanProcessor"); + throw UnsupportedException(die); } std::unique_ptr SdkBuilder::CreateExtensionSpanProcessor( @@ -1181,28 +1137,14 @@ std::unique_ptr &model) const { - using opentelemetry::sdk::instrumentationscope::InstrumentationScope; - using opentelemetry::sdk::instrumentationscope::ScopeConfigurator; - using opentelemetry::sdk::trace::TracerConfig; - - TracerConfig default_config = - model->default_config.enabled ? TracerConfig::Enabled() : TracerConfig::Disabled(); - - auto builder = ScopeConfigurator::Builder(default_config); - - for (const auto &entry : model->tracers) + const TracerConfiguratorBuilder *builder = registry_->GetTracerConfiguratorBuilder(); + if (builder != nullptr) { - TracerConfig entry_config = - entry.config.enabled ? TracerConfig::Enabled() : TracerConfig::Disabled(); - std::string pattern = entry.name; - builder.AddCondition( - [pattern](const InstrumentationScope &scope) { - return WildcardMatch(pattern, scope.GetName()); - }, - entry_config); + OTEL_INTERNAL_LOG_DEBUG("CreateTracerConfigurator() using registered builder"); + return builder->Build(model.get()); } - - return std::make_unique>(builder.Build()); + static const std::string die("No builder for TracerConfigurator"); + throw UnsupportedException(die); } std::unique_ptr SdkBuilder::CreateTracerProvider( @@ -1223,8 +1165,8 @@ std::unique_ptr SdkBuilder::CreateTra else { // Spec default: parentbased_always_on - sampler = opentelemetry::sdk::trace::ParentBasedSamplerFactory::Create( - opentelemetry::sdk::trace::AlwaysOnSamplerFactory::Create()); + static const opentelemetry::sdk::configuration::ParentBasedSamplerConfiguration kDefault; + sampler = CreateParentBasedSampler(&kDefault); } std::vector> sdk_processors; @@ -1255,15 +1197,10 @@ std::unique_ptr SdkBuilder::CreateTra } else { - auto id_generator = opentelemetry::sdk::trace::RandomIdGeneratorFactory::Create(); - auto tracer_configurator = - std::make_unique>( - opentelemetry::sdk::instrumentationscope:: - ScopeConfigurator::Builder( - opentelemetry::sdk::trace::TracerConfig::Default()) - .Build()); - sdk = opentelemetry::sdk::trace::TracerProviderFactory::Create( + auto default_model = std::make_unique(); + auto tracer_configurator = CreateTracerConfigurator(default_model); + auto id_generator = opentelemetry::sdk::trace::RandomIdGeneratorFactory::Create(); + sdk = opentelemetry::sdk::trace::TracerProviderFactory::Create( std::move(sdk_processors), resource, std::move(sampler), std::move(id_generator), std::move(tracer_configurator), span_limits); } @@ -1827,28 +1764,14 @@ std::unique_ptr &model) const { - using opentelemetry::sdk::instrumentationscope::InstrumentationScope; - using opentelemetry::sdk::instrumentationscope::ScopeConfigurator; - using opentelemetry::sdk::metrics::MeterConfig; - - MeterConfig default_config = - model->default_config.enabled ? MeterConfig::Enabled() : MeterConfig::Disabled(); - - auto builder = ScopeConfigurator::Builder(default_config); - - for (const auto &entry : model->meters) + const MeterConfiguratorBuilder *builder = registry_->GetMeterConfiguratorBuilder(); + if (builder != nullptr) { - MeterConfig entry_config = - entry.config.enabled ? MeterConfig::Enabled() : MeterConfig::Disabled(); - std::string pattern = entry.name; - builder.AddCondition( - [pattern](const InstrumentationScope &scope) { - return WildcardMatch(pattern, scope.GetName()); - }, - entry_config); + OTEL_INTERNAL_LOG_DEBUG("CreateMeterConfigurator() using registered builder"); + return builder->Build(model.get()); } - - return std::make_unique>(builder.Build()); + static const std::string die("No builder for MeterConfigurator"); + throw UnsupportedException(die); } std::unique_ptr SdkBuilder::CreateMeterProvider( @@ -1873,8 +1796,10 @@ std::unique_ptr SdkBuilder::CreateMe } else { - meter_context = opentelemetry::sdk::metrics::MeterContextFactory::Create( - std::move(view_registry), resource); + auto default_model = std::make_unique(); + auto meter_configurator = CreateMeterConfigurator(default_model); + meter_context = opentelemetry::sdk::metrics::MeterContextFactory::Create( + std::move(view_registry), resource, std::move(meter_configurator)); } for (const auto &reader_configuration : model->readers) @@ -2008,33 +1933,32 @@ std::unique_ptr SdkBuilder::CreateBatchLogRecordProcessor( const opentelemetry::sdk::configuration::BatchLogRecordProcessorConfiguration *model) const { - std::unique_ptr sdk; - opentelemetry::sdk::logs::BatchLogRecordProcessorOptions options; - - options.schedule_delay_millis = std::chrono::milliseconds(model->schedule_delay); - options.export_timeout_millis = std::chrono::milliseconds(model->export_timeout); - options.max_queue_size = model->max_queue_size; - options.max_export_batch_size = model->max_export_batch_size; - auto exporter_sdk = CreateLogRecordExporter(model->exporter); - sdk = opentelemetry::sdk::logs::BatchLogRecordProcessorFactory::Create(std::move(exporter_sdk), - options); - - return sdk; + const BatchLogRecordProcessorBuilder *builder = registry_->GetBatchLogRecordProcessorBuilder(); + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateBatchLogRecordProcessor() using registered builder"); + return builder->Build(model, std::move(exporter_sdk)); + } + static const std::string die("No builder for BatchLogRecordProcessor"); + throw UnsupportedException(die); } std::unique_ptr SdkBuilder::CreateSimpleLogRecordProcessor( const opentelemetry::sdk::configuration::SimpleLogRecordProcessorConfiguration *model) const { - std::unique_ptr sdk; - auto exporter_sdk = CreateLogRecordExporter(model->exporter); - sdk = opentelemetry::sdk::logs::SimpleLogRecordProcessorFactory::Create(std::move(exporter_sdk)); - - return sdk; + const SimpleLogRecordProcessorBuilder *builder = registry_->GetSimpleLogRecordProcessorBuilder(); + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("CreateSimpleLogRecordProcessor() using registered builder"); + return builder->Build(model, std::move(exporter_sdk)); + } + static const std::string die("No builder for SimpleLogRecordProcessor"); + throw UnsupportedException(die); } std::unique_ptr @@ -2078,30 +2002,14 @@ std::unique_ptr &model) const { - using opentelemetry::sdk::instrumentationscope::InstrumentationScope; - using opentelemetry::sdk::instrumentationscope::ScopeConfigurator; - using opentelemetry::sdk::logs::LoggerConfig; - - LoggerConfig default_config = LoggerConfig::Create( - model->default_config.enabled, ToLogSeverity(model->default_config.minimum_severity), - model->default_config.trace_based); - - auto builder = ScopeConfigurator::Builder(default_config); - - for (const auto &entry : model->loggers) + const LoggerConfiguratorBuilder *builder = registry_->GetLoggerConfiguratorBuilder(); + if (builder != nullptr) { - LoggerConfig entry_config = - LoggerConfig::Create(entry.config.enabled, ToLogSeverity(entry.config.minimum_severity), - entry.config.trace_based); - std::string pattern = entry.name; - builder.AddCondition( - [pattern](const InstrumentationScope &scope) { - return WildcardMatch(pattern, scope.GetName()); - }, - entry_config); + OTEL_INTERNAL_LOG_DEBUG("CreateLoggerConfigurator() using registered builder"); + return builder->Build(model.get()); } - - return std::make_unique>(builder.Build()); + static const std::string die("No builder for LoggerConfigurator"); + throw UnsupportedException(die); } std::unique_ptr SdkBuilder::CreateLoggerProvider( @@ -2133,13 +2041,8 @@ std::unique_ptr SdkBuilder::CreateLogg } else { - logger_configurator = - std::make_unique>( - opentelemetry::sdk::instrumentationscope:: - ScopeConfigurator::Builder( - opentelemetry::sdk::logs::LoggerConfig::Default()) - .Build()); + auto default_model = std::make_unique(); + logger_configurator = CreateLoggerConfigurator(default_model); } sdk = opentelemetry::sdk::logs::LoggerProviderFactory::Create( From d077f5f166c71c15e5eafec35019bba9d22d7476 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Wed, 5 Aug 2026 15:12:41 -0400 Subject: [PATCH 06/20] add registry factory --- .../sdk/configuration/registry_factory.h | 26 ++++++++++++++++ sdk/src/configuration/registry_factory.cc | 30 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 sdk/include/opentelemetry/sdk/configuration/registry_factory.h create mode 100644 sdk/src/configuration/registry_factory.cc diff --git a/sdk/include/opentelemetry/sdk/configuration/registry_factory.h b/sdk/include/opentelemetry/sdk/configuration/registry_factory.h new file mode 100644 index 0000000000..bb090ca32e --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/registry_factory.h @@ -0,0 +1,26 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/registry.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class RegistryFactory +{ +public: + // Returns a Registry pre-populated with all default signal builders. + static std::shared_ptr Create(); +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/src/configuration/registry_factory.cc b/sdk/src/configuration/registry_factory.cc new file mode 100644 index 0000000000..4bf720f51b --- /dev/null +++ b/sdk/src/configuration/registry_factory.cc @@ -0,0 +1,30 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include "opentelemetry/sdk/configuration/registry_factory.h" + +#include + +#include "opentelemetry/sdk/configuration/logs_builders.h" +#include "opentelemetry/sdk/configuration/metrics_builders.h" +#include "opentelemetry/sdk/configuration/registry.h" +#include "opentelemetry/sdk/configuration/trace_builders.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +std::shared_ptr RegistryFactory::Create() +{ + auto registry = std::make_shared(); + RegisterDefaultTraceBuilders(registry.get()); + RegisterDefaultMetricsBuilders(registry.get()); + RegisterDefaultLogsBuilders(registry.get()); + return registry; +} + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE From 88bba8e69743d0be1c68576beff978c6fd077dd0 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Wed, 5 Aug 2026 15:31:17 -0400 Subject: [PATCH 07/20] Update CMake and Bazel build files for sdk/configuration --- sdk/CMakeLists.txt | 4 ++ sdk/src/configuration/BUILD | 54 ++++++++++++++++++++ sdk/src/configuration/CMakeLists.txt | 73 ++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) diff --git a/sdk/CMakeLists.txt b/sdk/CMakeLists.txt index 8e7d5e9def..2562571bbc 100644 --- a/sdk/CMakeLists.txt +++ b/sdk/CMakeLists.txt @@ -26,6 +26,10 @@ otel_add_component( opentelemetry_trace opentelemetry_metrics opentelemetry_configuration_core + opentelemetry_configuration_trace_builders + opentelemetry_configuration_metrics_builders + opentelemetry_configuration_logs_builders + opentelemetry_configuration_registry_factory FILES_DIRECTORY "include/opentelemetry/" FILES_DESTINATION diff --git a/sdk/src/configuration/BUILD b/sdk/src/configuration/BUILD index c9b8d25928..48e6b0ed0b 100644 --- a/sdk/src/configuration/BUILD +++ b/sdk/src/configuration/BUILD @@ -23,6 +23,60 @@ cc_library( "//api", "//sdk:headers", "//sdk/src/common:wildcard_match", + "//sdk/src/logs", + "//sdk/src/metrics", + "//sdk/src/trace", + ], +) + +cc_library( + name = "configuration_trace_builders", + srcs = ["trace_builders.cc"], + include_prefix = "src/configuration", + deps = [ + ":configuration_core", + "//api", + "//sdk:headers", + "//sdk/src/common:wildcard_match", + ], +) + +cc_library( + name = "configuration_logs_builders", + srcs = ["logs_builders.cc"], + include_prefix = "src/configuration", + deps = [ + ":configuration_core", + "//api", + "//sdk:headers", + "//sdk/src/common:wildcard_match", + ], +) + +cc_library( + name = "configuration_metrics_builders", + srcs = ["metrics_builders.cc"], + include_prefix = "src/configuration", + deps = [ + ":configuration_core", + "//api", + "//sdk:headers", + "//sdk/src/common:wildcard_match", + "//sdk/src/metrics", + ], +) + +cc_library( + name = "configuration_registry_factory", + srcs = ["registry_factory.cc"], + include_prefix = "src/configuration", + deps = [ + ":configuration_core", + ":configuration_logs_builders", + ":configuration_metrics_builders", + ":configuration_trace_builders", + "//api", + "//sdk:headers", ], ) diff --git a/sdk/src/configuration/CMakeLists.txt b/sdk/src/configuration/CMakeLists.txt index b4f9b364bb..c885d35626 100644 --- a/sdk/src/configuration/CMakeLists.txt +++ b/sdk/src/configuration/CMakeLists.txt @@ -1,6 +1,8 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 +# Configuration Core: Builder interfaces, Configuration model, Registry, SDK +# Builder, Configured SDK add_library( opentelemetry_configuration_core document_node.cc @@ -27,8 +29,79 @@ target_link_libraries( opentelemetry_metrics opentelemetry_logs PRIVATE) +# Trace SDK component builders +add_library(opentelemetry_configuration_trace_builders trace_builders.cc) + +set_target_properties(opentelemetry_configuration_trace_builders + PROPERTIES EXPORT_NAME configuration_trace_builders) +set_target_version(opentelemetry_configuration_trace_builders) + +target_include_directories( + opentelemetry_configuration_trace_builders + PUBLIC "$" + "$") + +target_link_libraries( + opentelemetry_configuration_trace_builders + PUBLIC opentelemetry_trace + PRIVATE opentelemetry_configuration_core) + +# Logs SDK component builders +add_library(opentelemetry_configuration_logs_builders logs_builders.cc) + +set_target_properties(opentelemetry_configuration_logs_builders + PROPERTIES EXPORT_NAME configuration_logs_builders) +set_target_version(opentelemetry_configuration_logs_builders) + +target_include_directories( + opentelemetry_configuration_logs_builders + PUBLIC "$" + "$") + +target_link_libraries( + opentelemetry_configuration_logs_builders + PUBLIC opentelemetry_logs + PRIVATE opentelemetry_configuration_core) + +# Metrics SDK component builders +add_library(opentelemetry_configuration_metrics_builders metrics_builders.cc) + +set_target_properties(opentelemetry_configuration_metrics_builders + PROPERTIES EXPORT_NAME configuration_metrics_builders) +set_target_version(opentelemetry_configuration_metrics_builders) + +target_include_directories( + opentelemetry_configuration_metrics_builders + PUBLIC "$" + "$") + +target_link_libraries( + opentelemetry_configuration_metrics_builders + PUBLIC opentelemetry_metrics + PRIVATE opentelemetry_configuration_core) + +# Registry factory for to register all SDK component builders +add_library(opentelemetry_configuration_registry_factory registry_factory.cc) + +set_target_properties(opentelemetry_configuration_registry_factory + PROPERTIES EXPORT_NAME configuration_registry_factory) +set_target_version(opentelemetry_configuration_registry_factory) + +target_include_directories( + opentelemetry_configuration_registry_factory + PUBLIC "$" + "$") + +target_link_libraries( + opentelemetry_configuration_registry_factory + PUBLIC opentelemetry_configuration_core + opentelemetry_configuration_trace_builders + opentelemetry_configuration_metrics_builders + opentelemetry_configuration_logs_builders) + if(WITH_CONFIGURATION) + # YAML configuration parser add_library( opentelemetry_configuration configuration_parser.cc yaml_configuration_parser.cc ryml_document.cc From a3442f37fc99f78ec2777eb76e82c4793693feba Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Wed, 5 Aug 2026 15:35:59 -0400 Subject: [PATCH 08/20] update sdk configuration tests --- sdk/test/configuration/BUILD | 57 ++++++++++++++++++- sdk/test/configuration/CMakeLists.txt | 46 ++++++++++++++- sdk/test/configuration/config_test_common.h | 37 ++++++++++++ sdk/test/configuration/configured_sdk_test.cc | 7 ++- sdk/test/configuration/logs_builders_test.cc | 31 ++++++++++ .../configuration/metrics_builders_test.cc | 29 ++++++++++ .../programmatic_configuration_test.cc | 23 ++++---- sdk/test/configuration/sdk_builder_test.cc | 23 ++++---- sdk/test/configuration/trace_builders_test.cc | 53 +++++++++++++++++ 9 files changed, 278 insertions(+), 28 deletions(-) create mode 100644 sdk/test/configuration/logs_builders_test.cc create mode 100644 sdk/test/configuration/metrics_builders_test.cc create mode 100644 sdk/test/configuration/trace_builders_test.cc diff --git a/sdk/test/configuration/BUILD b/sdk/test/configuration/BUILD index 2593140d78..897533ceac 100644 --- a/sdk/test/configuration/BUILD +++ b/sdk/test/configuration/BUILD @@ -35,7 +35,7 @@ cc_test( ], deps = [ "//sdk:headers", - "//sdk/src/configuration:configuration_core", + "//sdk/src/configuration:configuration_registry_factory", "//sdk/src/logs", "//sdk/src/metrics", "//sdk/src/resource", @@ -56,7 +56,7 @@ cc_test( ], deps = [ "//sdk:headers", - "//sdk/src/configuration:configuration_core", + "//sdk/src/configuration:configuration_registry_factory", "//sdk/src/logs", "//sdk/src/metrics", "//sdk/src/resource", @@ -77,7 +77,7 @@ cc_test( ], deps = [ "//sdk:headers", - "//sdk/src/configuration:configuration_core", + "//sdk/src/configuration:configuration_registry_factory", "//sdk/src/logs", "//sdk/src/metrics", "//sdk/src/resource", @@ -86,6 +86,57 @@ cc_test( ], ) +cc_test( + name = "trace_builders_test", + srcs = [ + "trace_builders_test.cc", + ], + tags = [ + "config", + "test", + ], + deps = [ + "//sdk:headers", + "//sdk/src/configuration:configuration_trace_builders", + "//sdk/src/trace", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "logs_builders_test", + srcs = [ + "logs_builders_test.cc", + ], + tags = [ + "config", + "test", + ], + deps = [ + "//sdk:headers", + "//sdk/src/configuration:configuration_logs_builders", + "//sdk/src/logs", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "metrics_builders_test", + srcs = [ + "metrics_builders_test.cc", + ], + tags = [ + "config", + "test", + ], + deps = [ + "//sdk:headers", + "//sdk/src/configuration:configuration_metrics_builders", + "//sdk/src/metrics", + "@com_google_googletest//:gtest_main", + ], +) + cc_test( name = "yaml_logs_test", srcs = [ diff --git a/sdk/test/configuration/CMakeLists.txt b/sdk/test/configuration/CMakeLists.txt index 87ed167de8..7d5f2079a0 100644 --- a/sdk/test/configuration/CMakeLists.txt +++ b/sdk/test/configuration/CMakeLists.txt @@ -1,12 +1,54 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -foreach(testname registry_test sdk_builder_test configured_sdk_test +add_executable(registry_test registry_test.cc) +target_link_libraries( + registry_test PRIVATE ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} + opentelemetry_configuration_core) +gtest_add_tests( + TARGET registry_test + TEST_PREFIX config. + TEST_LIST registry_test) + +add_executable(trace_builders_test trace_builders_test.cc) +target_link_libraries( + trace_builders_test + PRIVATE ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} + opentelemetry_configuration_trace_builders + opentelemetry_configuration_core) +gtest_add_tests( + TARGET trace_builders_test + TEST_PREFIX config. + TEST_LIST trace_builders_test) + +add_executable(logs_builders_test logs_builders_test.cc) +target_link_libraries( + logs_builders_test + PRIVATE ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} + opentelemetry_configuration_logs_builders + opentelemetry_configuration_core) +gtest_add_tests( + TARGET logs_builders_test + TEST_PREFIX config. + TEST_LIST logs_builders_test) + +add_executable(metrics_builders_test metrics_builders_test.cc) +target_link_libraries( + metrics_builders_test + PRIVATE ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} + opentelemetry_configuration_metrics_builders + opentelemetry_configuration_core) +gtest_add_tests( + TARGET metrics_builders_test + TEST_PREFIX config. + TEST_LIST metrics_builders_test) + +foreach(testname sdk_builder_test configured_sdk_test programmatic_configuration_test) add_executable(${testname} "${testname}.cc") target_link_libraries( ${testname} PRIVATE ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} - opentelemetry_configuration_core) + opentelemetry_configuration_registry_factory) gtest_add_tests( TARGET ${testname} TEST_PREFIX config. diff --git a/sdk/test/configuration/config_test_common.h b/sdk/test/configuration/config_test_common.h index 02629fa1a6..a8db8544d1 100644 --- a/sdk/test/configuration/config_test_common.h +++ b/sdk/test/configuration/config_test_common.h @@ -28,6 +28,10 @@ #include "opentelemetry/context/propagation/text_map_propagator.h" #include "opentelemetry/nostd/span.h" #include "opentelemetry/sdk/common/exporter_utils.h" +#include "opentelemetry/sdk/configuration/batch_log_record_processor_builder.h" +#include "opentelemetry/sdk/configuration/batch_log_record_processor_configuration.h" +#include "opentelemetry/sdk/configuration/batch_span_processor_builder.h" +#include "opentelemetry/sdk/configuration/batch_span_processor_configuration.h" #include "opentelemetry/sdk/configuration/extension_log_record_exporter_builder.h" #include "opentelemetry/sdk/configuration/extension_log_record_exporter_configuration.h" #include "opentelemetry/sdk/configuration/extension_push_metric_exporter_builder.h" @@ -36,14 +40,18 @@ #include "opentelemetry/sdk/configuration/extension_span_exporter_configuration.h" #include "opentelemetry/sdk/configuration/periodic_metric_reader_builder.h" #include "opentelemetry/sdk/configuration/periodic_metric_reader_configuration.h" +#include "opentelemetry/sdk/configuration/simple_log_record_processor_configuration.h" +#include "opentelemetry/sdk/configuration/simple_span_processor_configuration.h" #include "opentelemetry/sdk/logs/exporter.h" #include "opentelemetry/sdk/logs/read_write_log_record.h" +#include "opentelemetry/sdk/logs/simple_log_record_processor.h" #include "opentelemetry/sdk/metrics/data/metric_data.h" #include "opentelemetry/sdk/metrics/export/metric_producer.h" #include "opentelemetry/sdk/metrics/instruments.h" #include "opentelemetry/sdk/metrics/metric_reader.h" #include "opentelemetry/sdk/metrics/push_metric_exporter.h" #include "opentelemetry/sdk/trace/exporter.h" +#include "opentelemetry/sdk/trace/simple_processor.h" #include "opentelemetry/sdk/trace/span_data.h" namespace config_test @@ -421,6 +429,35 @@ class CapturingPeriodicMetricReaderBuilder std::shared_ptr captured_; }; +// --------------------------------------------------------------------------- +// Mock batch processor builders: satisfy the batch builder interface but +// create simple (synchronous) processors to avoid background-thread races in tests. + +class MockBatchSpanProcessorBuilder + : public opentelemetry::sdk::configuration::BatchSpanProcessorBuilder +{ +public: + std::unique_ptr Build( + const opentelemetry::sdk::configuration::BatchSpanProcessorConfiguration *, + std::unique_ptr &&exporter) const override + { + return std::make_unique(std::move(exporter)); + } +}; + +class MockBatchLogRecordProcessorBuilder + : public opentelemetry::sdk::configuration::BatchLogRecordProcessorBuilder +{ +public: + std::unique_ptr Build( + const opentelemetry::sdk::configuration::BatchLogRecordProcessorConfiguration *, + std::unique_ptr &&exporter) const override + { + return std::make_unique( + std::move(exporter)); + } +}; + // --------------------------------------------------------------------------- // TextMapCarrier for propagator tests. diff --git a/sdk/test/configuration/configured_sdk_test.cc b/sdk/test/configuration/configured_sdk_test.cc index 8ff9532a13..ac4ea180a1 100644 --- a/sdk/test/configuration/configured_sdk_test.cc +++ b/sdk/test/configuration/configured_sdk_test.cc @@ -36,6 +36,7 @@ #include "opentelemetry/sdk/configuration/propagator_configuration.h" #include "opentelemetry/sdk/configuration/push_metric_exporter_configuration.h" #include "opentelemetry/sdk/configuration/registry.h" +#include "opentelemetry/sdk/configuration/registry_factory.h" #include "opentelemetry/sdk/configuration/resource_configuration.h" #include "opentelemetry/sdk/configuration/severity_number.h" #include "opentelemetry/sdk/configuration/simple_log_record_processor_configuration.h" @@ -113,7 +114,7 @@ class ConfiguredSdkTest : public ::testing::Test void MakeRegistry() { - registry_ = std::make_shared(); + registry_ = config_sdk::RegistryFactory::Create(); registry_->SetExtensionSpanExporterBuilder( "noop", std::make_unique()); registry_->SetExtensionLogRecordExporterBuilder( @@ -122,6 +123,10 @@ class ConfiguredSdkTest : public ::testing::Test "noop", std::make_unique()); registry_->SetPeriodicMetricReaderBuilder( std::make_unique()); + registry_->SetBatchSpanProcessorBuilder( + std::make_unique()); + registry_->SetBatchLogRecordProcessorBuilder( + std::make_unique()); } static std::unique_ptr MakeTracerProviderConfig() diff --git a/sdk/test/configuration/logs_builders_test.cc b/sdk/test/configuration/logs_builders_test.cc new file mode 100644 index 0000000000..59a73c2b0e --- /dev/null +++ b/sdk/test/configuration/logs_builders_test.cc @@ -0,0 +1,31 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include +#include + +#include "opentelemetry/sdk/configuration/logs_builders.h" +#include "opentelemetry/sdk/configuration/registry.h" + +namespace configuration = opentelemetry::sdk::configuration; + +TEST(LogsBuilders, EmptyRegistryHasNoLogsBuilders) +{ + auto registry = std::make_shared(); + + EXPECT_EQ(registry->GetBatchLogRecordProcessorBuilder(), nullptr); + EXPECT_EQ(registry->GetSimpleLogRecordProcessorBuilder(), nullptr); + EXPECT_EQ(registry->GetLoggerConfiguratorBuilder(), nullptr); +} + +TEST(LogsBuilders, RegisterDefaultLogsBuildersFillesAllLogsSlots) +{ + auto registry = std::make_shared(); + + configuration::RegisterDefaultLogsBuilders(registry.get()); + + EXPECT_NE(registry->GetBatchLogRecordProcessorBuilder(), nullptr); + EXPECT_NE(registry->GetSimpleLogRecordProcessorBuilder(), nullptr); + EXPECT_NE(registry->GetLoggerConfiguratorBuilder(), nullptr); +} diff --git a/sdk/test/configuration/metrics_builders_test.cc b/sdk/test/configuration/metrics_builders_test.cc new file mode 100644 index 0000000000..92c7af681e --- /dev/null +++ b/sdk/test/configuration/metrics_builders_test.cc @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include +#include + +#include "opentelemetry/sdk/configuration/metrics_builders.h" +#include "opentelemetry/sdk/configuration/registry.h" + +namespace configuration = opentelemetry::sdk::configuration; + +TEST(MetricsBuilders, EmptyRegistryHasNoMetricsBuilders) +{ + auto registry = std::make_shared(); + + EXPECT_EQ(registry->GetPeriodicMetricReaderBuilder(), nullptr); + EXPECT_EQ(registry->GetMeterConfiguratorBuilder(), nullptr); +} + +TEST(MetricsBuilders, RegisterDefaultMetricsBuildersFillesAllMetricsSlots) +{ + auto registry = std::make_shared(); + + configuration::RegisterDefaultMetricsBuilders(registry.get()); + + EXPECT_NE(registry->GetPeriodicMetricReaderBuilder(), nullptr); + EXPECT_NE(registry->GetMeterConfiguratorBuilder(), nullptr); +} diff --git a/sdk/test/configuration/programmatic_configuration_test.cc b/sdk/test/configuration/programmatic_configuration_test.cc index cee81c182f..b7a2be6d04 100644 --- a/sdk/test/configuration/programmatic_configuration_test.cc +++ b/sdk/test/configuration/programmatic_configuration_test.cc @@ -43,7 +43,9 @@ #include "opentelemetry/sdk/configuration/aggregation_configuration.h" #include "opentelemetry/sdk/configuration/always_off_sampler_configuration.h" #include "opentelemetry/sdk/configuration/base2_exponential_bucket_histogram_aggregation_configuration.h" +#include "opentelemetry/sdk/configuration/batch_log_record_processor_builder.h" #include "opentelemetry/sdk/configuration/batch_log_record_processor_configuration.h" +#include "opentelemetry/sdk/configuration/batch_span_processor_builder.h" #include "opentelemetry/sdk/configuration/batch_span_processor_configuration.h" #include "opentelemetry/sdk/configuration/configuration.h" #include "opentelemetry/sdk/configuration/configured_sdk.h" @@ -73,6 +75,7 @@ #include "opentelemetry/sdk/configuration/propagator_configuration.h" #include "opentelemetry/sdk/configuration/push_metric_exporter_configuration.h" #include "opentelemetry/sdk/configuration/registry.h" +#include "opentelemetry/sdk/configuration/registry_factory.h" #include "opentelemetry/sdk/configuration/resource_configuration.h" #include "opentelemetry/sdk/configuration/sampler_configuration.h" #include "opentelemetry/sdk/configuration/severity_number.h" @@ -152,7 +155,7 @@ class ProgrammaticConfigTest : public ::testing::Test void MakeRegistry() { - registry_ = std::make_shared(); + registry_ = config_sdk::RegistryFactory::Create(); registry_->SetExtensionSpanExporterBuilder( "recording", std::make_unique(span_buffer_)); registry_->SetExtensionLogRecordExporterBuilder( @@ -162,6 +165,10 @@ class ProgrammaticConfigTest : public ::testing::Test std::make_unique(metric_buffer_)); registry_->SetPeriodicMetricReaderBuilder( std::make_unique()); + registry_->SetBatchSpanProcessorBuilder( + std::make_unique()); + registry_->SetBatchLogRecordProcessorBuilder( + std::make_unique()); } static std::unique_ptr MakeTracerProviderConfig() @@ -367,10 +374,7 @@ TEST_F(ProgrammaticConfigTest, LoggerProviderWithLoggerConfigurator) EXPECT_EQ(log_buffer_->size(), 2); } -// TODO: Re-enable this test once a mock BatchSpanProcessor can be configured. -// All tests that use a BatchProcessor may timeout due to the a race between the background thread -// and the ForceFlush call. -TEST_F(ProgrammaticConfigTest, DISABLED_LoggerProviderWithBatchProcessorDefaults) +TEST_F(ProgrammaticConfigTest, LoggerProviderWithBatchProcessorDefaults) { auto exporter = std::make_unique(); exporter->name = "recording"; @@ -392,8 +396,7 @@ TEST_F(ProgrammaticConfigTest, DISABLED_LoggerProviderWithBatchProcessorDefaults EXPECT_GE(log_buffer_->size(), 1); } -// TODO: Re-enable this test once a mock BatchProcessor can be configured. -TEST_F(ProgrammaticConfigTest, DISABLED_LoggerProviderWithBatchProcessorConfigured) +TEST_F(ProgrammaticConfigTest, LoggerProviderWithBatchProcessorConfigured) { auto exporter = std::make_unique(); exporter->name = "recording"; @@ -659,8 +662,7 @@ TEST_F(ProgrammaticConfigTest, TracerProviderWithParentBasedSamplerNullRoot) EXPECT_EQ(span_buffer_->size(), 1); } -// TODO: Re-enable this test once a mock BatchSpanProcessor can be configured. -TEST_F(ProgrammaticConfigTest, DISABLED_TracerProviderWithBatchProcessor) +TEST_F(ProgrammaticConfigTest, TracerProviderWithBatchProcessor) { auto exporter = std::make_unique(); exporter->name = "recording"; @@ -681,8 +683,7 @@ TEST_F(ProgrammaticConfigTest, DISABLED_TracerProviderWithBatchProcessor) EXPECT_GE(span_buffer_->size(), 1); } -// TODO: Re-enable this test once a mock BatchSpanProcessor can be configured. -TEST_F(ProgrammaticConfigTest, DISABLED_TracerProviderWithBatchProcessorConfigured) +TEST_F(ProgrammaticConfigTest, TracerProviderWithBatchProcessorConfigured) { auto exporter = std::make_unique(); exporter->name = "recording"; diff --git a/sdk/test/configuration/sdk_builder_test.cc b/sdk/test/configuration/sdk_builder_test.cc index 5a47530a0b..7a59f007d0 100644 --- a/sdk/test/configuration/sdk_builder_test.cc +++ b/sdk/test/configuration/sdk_builder_test.cc @@ -27,6 +27,7 @@ #include "opentelemetry/sdk/configuration/probability_sampler_configuration.h" #include "opentelemetry/sdk/configuration/push_metric_exporter_configuration.h" #include "opentelemetry/sdk/configuration/registry.h" +#include "opentelemetry/sdk/configuration/registry_factory.h" #include "opentelemetry/sdk/configuration/sampler_configuration.h" #include "opentelemetry/sdk/configuration/sdk_builder.h" #include "opentelemetry/sdk/configuration/severity_number.h" @@ -55,7 +56,7 @@ #include "opentelemetry/sdk/trace/span_limits.h" #include "opentelemetry/sdk/trace/tracer_provider.h" -using opentelemetry::sdk::configuration::Registry; +using opentelemetry::sdk::configuration::RegistryFactory; using opentelemetry::sdk::configuration::SdkBuilder; using opentelemetry::sdk::configuration::SpanLimitsConfiguration; using opentelemetry::sdk::configuration::TracerProviderConfiguration; @@ -76,7 +77,7 @@ TEST(SdkBuilder, SpanLimitsDefaults) auto model = std::make_unique(); model->limits = nullptr; - SdkBuilder builder(std::make_shared()); + SdkBuilder builder(RegistryFactory::Create()); auto resource = opentelemetry::sdk::resource::Resource::Create({}); auto provider = builder.CreateTracerProvider(model, resource); ASSERT_NE(provider, nullptr); @@ -103,7 +104,7 @@ TEST(SdkBuilder, SpanLimitsConfiguration) model->limits->event_attribute_count_limit = 5555; model->limits->link_attribute_count_limit = 6666; - SdkBuilder builder(std::make_shared()); + SdkBuilder builder(RegistryFactory::Create()); auto resource = opentelemetry::sdk::resource::Resource::Create({}); auto provider = builder.CreateTracerProvider(model, resource); ASSERT_NE(provider, nullptr); @@ -141,7 +142,7 @@ TEST(SdkBuilder, CreateLoggerConfigurator) model->loggers.push_back(matcher1); model->loggers.push_back(matcher2); - config_sdk::SdkBuilder builder(std::make_shared()); + config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto logger_configurator = builder.CreateLoggerConfigurator(model); ASSERT_NE(logger_configurator, nullptr); @@ -175,7 +176,7 @@ TEST(SdkBuilder, CreateParentBasedSampler) { config_sdk::ParentBasedSamplerConfiguration parent_based_sampler_config; parent_based_sampler_config.root = nullptr; - config_sdk::SdkBuilder builder(std::make_shared()); + config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateParentBasedSampler(&parent_based_sampler_config); ASSERT_NE(sampler, nullptr); EXPECT_EQ(std::string{sampler->GetDescription()}, R"(ParentBased{AlwaysOnSampler})"); @@ -185,7 +186,7 @@ TEST(SdkBuilder, CreateParentBasedSampler) { config_sdk::ParentBasedSamplerConfiguration parent_based_sampler_config; parent_based_sampler_config.root = std::make_unique(); - config_sdk::SdkBuilder builder(std::make_shared()); + config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateParentBasedSampler(&parent_based_sampler_config); ASSERT_NE(sampler, nullptr); EXPECT_EQ(std::string{sampler->GetDescription()}, R"(ParentBased{AlwaysOnSampler})"); @@ -196,7 +197,7 @@ TEST(SdkBuilder, CreateParentBasedSampler) config_sdk::ParentBasedSamplerConfiguration parent_based_sampler_config; parent_based_sampler_config.root = std::make_unique(); - config_sdk::SdkBuilder builder(std::make_shared()); + config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateParentBasedSampler(&parent_based_sampler_config); ASSERT_NE(sampler, nullptr); EXPECT_EQ(std::string{sampler->GetDescription()}, R"(ParentBased{AlwaysOffSampler})"); @@ -209,7 +210,7 @@ TEST(SdkBuilder, CreateParentBasedSampler) std::make_unique(); trace_id_ratio_based_sampler_config->ratio = 0.5; parent_based_sampler_config.root = std::move(trace_id_ratio_based_sampler_config); - config_sdk::SdkBuilder builder(std::make_shared()); + config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateParentBasedSampler(&parent_based_sampler_config); ASSERT_NE(sampler, nullptr); EXPECT_EQ(std::string{sampler->GetDescription()}, @@ -240,7 +241,7 @@ TEST(SdkBuilder, CreateParentBasedSampler) std::make_unique(); parent_based_sampler_config.local_parent_not_sampled = std::move(always_off_sampler_config_2); - config_sdk::SdkBuilder builder(std::make_shared()); + config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateParentBasedSampler(&parent_based_sampler_config); ASSERT_NE(sampler, nullptr); EXPECT_EQ(std::string{sampler->GetDescription()}, @@ -253,7 +254,7 @@ TEST(SdkBuilder, CreateProbabilitySampler) // default ratio is 1.0 { config_sdk::ProbabilitySamplerConfiguration probability_sampler_config; - config_sdk::SdkBuilder builder(std::make_shared()); + config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateProbabilitySampler(&probability_sampler_config); ASSERT_NE(sampler, nullptr); EXPECT_EQ(std::string{sampler->GetDescription()}, R"(ProbabilitySampler{1.000000})"); @@ -266,7 +267,7 @@ TEST(SdkBuilder, CreateProbabilitySampler) probability_sampler_config->ratio = 0.5; std::unique_ptr sampler_config = std::move(probability_sampler_config); - config_sdk::SdkBuilder builder(std::make_shared()); + config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateSampler(sampler_config); ASSERT_NE(sampler, nullptr); EXPECT_EQ(std::string{sampler->GetDescription()}, R"(ProbabilitySampler{0.500000})"); diff --git a/sdk/test/configuration/trace_builders_test.cc b/sdk/test/configuration/trace_builders_test.cc new file mode 100644 index 0000000000..1a137c38e6 --- /dev/null +++ b/sdk/test/configuration/trace_builders_test.cc @@ -0,0 +1,53 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include +#include +#include + +#include "opentelemetry/sdk/configuration/registry.h" +#include "opentelemetry/sdk/configuration/trace_builders.h" + +namespace configuration = opentelemetry::sdk::configuration; + +TEST(TraceBuilders, EmptyRegistryHasNoTraceBuilders) +{ + auto registry = std::make_shared(); + + EXPECT_EQ(registry->GetAlwaysOnSamplerBuilder(), nullptr); + EXPECT_EQ(registry->GetAlwaysOffSamplerBuilder(), nullptr); + EXPECT_EQ(registry->GetTraceIdRatioBasedSamplerBuilder(), nullptr); + EXPECT_EQ(registry->GetProbabilitySamplerBuilder(), nullptr); + EXPECT_EQ(registry->GetParentBasedSamplerBuilder(), nullptr); + EXPECT_EQ(registry->GetJaegerRemoteSamplerBuilder(), nullptr); + EXPECT_EQ(registry->GetBatchSpanProcessorBuilder(), nullptr); + EXPECT_EQ(registry->GetSimpleSpanProcessorBuilder(), nullptr); + EXPECT_EQ(registry->GetTracerConfiguratorBuilder(), nullptr); + EXPECT_EQ(registry->GetComposableAlwaysOnSamplerBuilder(), nullptr); + EXPECT_EQ(registry->GetComposableAlwaysOffSamplerBuilder(), nullptr); + EXPECT_EQ(registry->GetComposableProbabilitySamplerBuilder(), nullptr); + EXPECT_EQ(registry->GetComposableParentThresholdSamplerBuilder(), nullptr); + EXPECT_EQ(registry->GetComposableRuleBasedSamplerBuilder(), nullptr); +} + +TEST(TraceBuilders, RegisterDefaultTraceBuildersFillsAllTraceSlots) +{ + auto registry = std::make_shared(); + + configuration::RegisterDefaultTraceBuilders(registry.get()); + + EXPECT_NE(registry->GetAlwaysOnSamplerBuilder(), nullptr); + EXPECT_NE(registry->GetAlwaysOffSamplerBuilder(), nullptr); + EXPECT_NE(registry->GetTraceIdRatioBasedSamplerBuilder(), nullptr); + EXPECT_NE(registry->GetProbabilitySamplerBuilder(), nullptr); + EXPECT_NE(registry->GetParentBasedSamplerBuilder(), nullptr); + EXPECT_NE(registry->GetJaegerRemoteSamplerBuilder(), nullptr); + EXPECT_NE(registry->GetBatchSpanProcessorBuilder(), nullptr); + EXPECT_NE(registry->GetSimpleSpanProcessorBuilder(), nullptr); + EXPECT_NE(registry->GetTracerConfiguratorBuilder(), nullptr); + EXPECT_NE(registry->GetComposableAlwaysOnSamplerBuilder(), nullptr); + EXPECT_NE(registry->GetComposableAlwaysOffSamplerBuilder(), nullptr); + EXPECT_NE(registry->GetComposableProbabilitySamplerBuilder(), nullptr); + EXPECT_NE(registry->GetComposableParentThresholdSamplerBuilder(), nullptr); + EXPECT_NE(registry->GetComposableRuleBasedSamplerBuilder(), nullptr); +} From d4c7101779c8e247126ca9159261d774eabd5df6 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Wed, 5 Aug 2026 16:18:20 -0400 Subject: [PATCH 09/20] update install tests to cover the new targets and headers --- .../configuration/CMakeLists.txt | 3 +- .../cmake/component_tests/sdk/CMakeLists.txt | 4 + .../cmake/fetch_content_test/CMakeLists.txt | 4 + install/test/src/test_configuration.cc | 5 +- install/test/src/test_sdk.cc | 282 ++++++++++++++++-- 5 files changed, 275 insertions(+), 23 deletions(-) diff --git a/install/test/cmake/component_tests/configuration/CMakeLists.txt b/install/test/cmake/component_tests/configuration/CMakeLists.txt index 5fef844f18..3cf1cf7353 100644 --- a/install/test/cmake/component_tests/configuration/CMakeLists.txt +++ b/install/test/cmake/component_tests/configuration/CMakeLists.txt @@ -17,7 +17,8 @@ include(GoogleTest) add_executable(configuration_test ${INSTALL_TEST_SRC_DIR}/test_configuration.cc) target_link_libraries( configuration_test - PRIVATE opentelemetry-cpp::configuration + PRIVATE opentelemetry-cpp::configuration_registry_factory + opentelemetry-cpp::configuration opentelemetry-cpp::ostream_log_record_exporter_builder opentelemetry-cpp::ostream_metrics_exporter_builder opentelemetry-cpp::ostream_span_exporter_builder diff --git a/install/test/cmake/component_tests/sdk/CMakeLists.txt b/install/test/cmake/component_tests/sdk/CMakeLists.txt index 747eec8862..6e57bb949c 100644 --- a/install/test/cmake/component_tests/sdk/CMakeLists.txt +++ b/install/test/cmake/component_tests/sdk/CMakeLists.txt @@ -25,6 +25,10 @@ target_link_libraries( opentelemetry-cpp::metrics opentelemetry-cpp::logs opentelemetry-cpp::configuration_core + opentelemetry-cpp::configuration_trace_builders + opentelemetry-cpp::configuration_metrics_builders + opentelemetry-cpp::configuration_logs_builders + opentelemetry-cpp::configuration_registry_factory GTest::gtest GTest::gtest_main) diff --git a/install/test/cmake/fetch_content_test/CMakeLists.txt b/install/test/cmake/fetch_content_test/CMakeLists.txt index 0c22b9f524..6180486a9b 100644 --- a/install/test/cmake/fetch_content_test/CMakeLists.txt +++ b/install/test/cmake/fetch_content_test/CMakeLists.txt @@ -79,6 +79,10 @@ target_link_libraries( opentelemetry-cpp::trace opentelemetry-cpp::logs opentelemetry-cpp::configuration_core + opentelemetry-cpp::configuration_trace_builders + opentelemetry-cpp::configuration_metrics_builders + opentelemetry-cpp::configuration_logs_builders + opentelemetry-cpp::configuration_registry_factory opentelemetry-cpp::configuration opentelemetry-cpp::resource_detectors opentelemetry-cpp::http_client diff --git a/install/test/src/test_configuration.cc b/install/test/src/test_configuration.cc index 7bd59ab5b7..a5ed8fcb49 100644 --- a/install/test/src/test_configuration.cc +++ b/install/test/src/test_configuration.cc @@ -10,12 +10,13 @@ #include "opentelemetry/sdk/configuration/configuration.h" #include "opentelemetry/sdk/configuration/configured_sdk.h" #include "opentelemetry/sdk/configuration/registry.h" +#include "opentelemetry/sdk/configuration/registry_factory.h" #include "opentelemetry/sdk/configuration/yaml_configuration_parser.h" TEST(ConfigurationInstallTest, ConfigurationCheck) { - std::shared_ptr registry( - new opentelemetry::sdk::configuration::Registry); + std::shared_ptr registry = + opentelemetry::sdk::configuration::RegistryFactory::Create(); EXPECT_NE(registry, nullptr); opentelemetry::exporter::trace::ConsoleSpanBuilder::Register(registry.get()); diff --git a/install/test/src/test_sdk.cc b/install/test/src/test_sdk.cc index b2e59e3279..9e666f1115 100644 --- a/install/test/src/test_sdk.cc +++ b/install/test/src/test_sdk.cc @@ -3,6 +3,7 @@ #include +// Include required API headers #include #include #include @@ -10,48 +11,289 @@ #include #include -#include -#include -#include +// SDK common headers +#include +#include +#include +// SDK instrumentation scope headers #include - +#include + +// SDK logs headers +#include +#include +#include +#include +#include #include -#include -#include -#include - -#include -#include -#include - +#include +#include +#include +#include +#include #include +#include #include +#include +#include +#include +#include #include +// SDK metrics headers +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include +#include +#include +#include +#include #include #include +#include #include +#include #include +#include +#include +#include +#include +#include +#include +#include + +// SDK resource headers +#include +#include -#include -#include -#include +// SDK trace headers +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// SDK version header +#include + +// SDK configuration model headers +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include #include -#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include +#include +#include #include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include +#include +#include + +// SDK configuration builder headers +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// SDK configuration primary builder headers +#include +#include +#include +#include +#include +#include +#include +#include namespace nostd = opentelemetry::nostd; namespace propagation = opentelemetry::context::propagation; @@ -356,7 +598,7 @@ TEST_F(SdkInstallTest, ConfigurationCoreCheck) { const std::string propagator_name{"noop"}; - auto registry = std::make_shared(); + auto registry = config_sdk::RegistryFactory::Create(); registry->SetConsoleSpanBuilder(std::make_unique()); registry->SetConsoleLogRecordBuilder(std::make_unique()); registry->SetConsolePushMetricExporterBuilder(std::make_unique()); From 460eb32e891448631e3605c7a1eb25dfb7e0d86e Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Wed, 5 Aug 2026 17:06:24 -0400 Subject: [PATCH 10/20] update configuration yaml example and test it --- examples/configuration/BUILD | 69 +++++++ examples/configuration/CMakeLists.txt | 21 +- examples/configuration/composite-sampler.yaml | 62 ++++++ .../custom_log_record_exporter.cc | 6 +- .../custom_log_record_processor.cc | 6 +- .../custom_pull_metric_exporter.cc | 8 +- .../custom_push_metric_exporter.cc | 8 +- .../configuration/custom_span_exporter.cc | 6 +- .../configuration/custom_span_processor.cc | 8 +- examples/configuration/extensions.yaml | 35 ++-- examples/configuration/kitchen-sink.yaml | 2 +- examples/configuration/main.cc | 5 +- examples/configuration/sdk-default.yaml | 185 ++++++++++++++++++ 13 files changed, 377 insertions(+), 44 deletions(-) create mode 100644 examples/configuration/composite-sampler.yaml create mode 100644 examples/configuration/sdk-default.yaml diff --git a/examples/configuration/BUILD b/examples/configuration/BUILD index f04cb00634..06e181e956 100644 --- a/examples/configuration/BUILD +++ b/examples/configuration/BUILD @@ -7,6 +7,12 @@ cc_test( name = "example_yaml", size = "medium", srcs = glob(["*.cc"]) + glob(["*.h"]), + args = [ + "--test", + "--yaml", + "$(location sdk-default.yaml)", + ], + data = ["sdk-default.yaml"], defines = [ "OTEL_HAVE_OTLP_HTTP", "OTEL_HAVE_OTLP_GRPC", @@ -36,6 +42,69 @@ cc_test( "//exporters/prometheus:prometheus_exporter_builder", "//sdk:headers", "//sdk/src/configuration", + "//sdk/src/configuration:configuration_registry_factory", + "//sdk/src/logs", + "//sdk/src/metrics", + "//sdk/src/trace", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "example_yaml_composite_sampler", + size = "medium", + srcs = glob(["*.cc"]) + glob(["*.h"]), + args = [ + "--test", + "--yaml", + "$(location composite-sampler.yaml)", + ], + data = ["composite-sampler.yaml"], + tags = [ + "test", + "yaml", + ], + deps = [ + "//api", + "//examples/common/logs_foo_library:common_logs_foo_library", + "//examples/common/metrics_foo_library:common_metrics_foo_library", + "//exporters/ostream:ostream_log_record_exporter_builder", + "//exporters/ostream:ostream_metric_exporter_builder", + "//exporters/ostream:ostream_span_exporter_builder", + "//sdk:headers", + "//sdk/src/configuration", + "//sdk/src/configuration:configuration_registry_factory", + "//sdk/src/logs", + "//sdk/src/metrics", + "//sdk/src/trace", + "@com_google_googletest//:gtest_main", + ], +) + +cc_test( + name = "example_yaml_extensions", + size = "medium", + srcs = glob(["*.cc"]) + glob(["*.h"]), + args = [ + "--test", + "--yaml", + "$(location extensions.yaml)", + ], + data = ["extensions.yaml"], + tags = [ + "test", + "yaml", + ], + deps = [ + "//api", + "//examples/common/logs_foo_library:common_logs_foo_library", + "//examples/common/metrics_foo_library:common_metrics_foo_library", + "//exporters/ostream:ostream_log_record_exporter_builder", + "//exporters/ostream:ostream_metric_exporter_builder", + "//exporters/ostream:ostream_span_exporter_builder", + "//sdk:headers", + "//sdk/src/configuration", + "//sdk/src/configuration:configuration_registry_factory", "//sdk/src/logs", "//sdk/src/metrics", "//sdk/src/trace", diff --git a/examples/configuration/CMakeLists.txt b/examples/configuration/CMakeLists.txt index 239a0cbd25..c52f04ff5c 100644 --- a/examples/configuration/CMakeLists.txt +++ b/examples/configuration/CMakeLists.txt @@ -69,10 +69,27 @@ if(DEFINED OPENTELEMETRY_BUILD_DLL) else() target_link_libraries( example_yaml - PRIVATE opentelemetry-cpp::configuration opentelemetry-cpp::common + PRIVATE opentelemetry-cpp::configuration_registry_factory + opentelemetry-cpp::configuration opentelemetry-cpp::common opentelemetry-cpp::trace opentelemetry-cpp::logs) endif() if(BUILD_TESTING) - add_test(NAME examples.example_yaml COMMAND "$") + add_test(NAME examples.example_yaml_sdk_default + COMMAND $ --test --yaml + ${CMAKE_CURRENT_SOURCE_DIR}/sdk-default.yaml) + set_tests_properties(examples.example_yaml_sdk_default + PROPERTIES FAIL_REGULAR_EXPRESSION "\\[ERROR\\]") + + add_test(NAME examples.example_yaml_composite_sampler + COMMAND $ --test --yaml + ${CMAKE_CURRENT_SOURCE_DIR}/composite-sampler.yaml) + set_tests_properties(examples.example_yaml_composite_sampler + PROPERTIES FAIL_REGULAR_EXPRESSION "\\[ERROR\\]") + + add_test(NAME examples.example_yaml_extensions + COMMAND $ --test --yaml + ${CMAKE_CURRENT_SOURCE_DIR}/extensions.yaml) + set_tests_properties(examples.example_yaml_extensions + PROPERTIES FAIL_REGULAR_EXPRESSION "\\[ERROR\\]") endif() diff --git a/examples/configuration/composite-sampler.yaml b/examples/configuration/composite-sampler.yaml new file mode 100644 index 0000000000..7c6a1af3d3 --- /dev/null +++ b/examples/configuration/composite-sampler.yaml @@ -0,0 +1,62 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# composite-sampler.yaml exercises all composite/development sampler builder types. + +file_format: "1.0" +log_level: info + +tracer_provider: + processors: + - simple: + exporter: + console: + sampler: + # parent_based sampler + parent_based: + root: + # rule_based composable sampler + composite/development: + rule_based: + rules: + - attribute_values: + key: http.method + values: + - GET + - POST + attribute_patterns: + key: http.url + included: + - .*/api/.* + excluded: + - .*/healthz + parent: + - remote + - local + span_kinds: + - server + - client + sampler: + always_on: + - sampler: + always_off: + remote_parent_sampled: + # always_on composable sampler + composite/development: + always_on: + remote_parent_not_sampled: + # always_off composable sampler + composite/development: + always_off: + local_parent_sampled: + # probability composable sampler + composite/development: + probability: + ratio: 0.5 + local_parent_not_sampled: + # parent_threshold composable sampler + composite/development: + parent_threshold: + root: + probability: + ratio: 0.1 diff --git a/examples/configuration/custom_log_record_exporter.cc b/examples/configuration/custom_log_record_exporter.cc index a69159153d..505cf98805 100644 --- a/examples/configuration/custom_log_record_exporter.cc +++ b/examples/configuration/custom_log_record_exporter.cc @@ -20,18 +20,18 @@ opentelemetry::sdk::common::ExportResult CustomLogRecordExporter::Export( const opentelemetry::nostd::span> & /* records */) noexcept { - OTEL_INTERNAL_LOG_ERROR("CustomLogRecordExporter::Export(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_WARN("CustomLogRecordExporter::Export(): YOUR CODE HERE"); return opentelemetry::sdk::common::ExportResult::kSuccess; } bool CustomLogRecordExporter::ForceFlush(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_ERROR("CustomLogRecordExporter::ForceFlush(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_WARN("CustomLogRecordExporter::ForceFlush(): YOUR CODE HERE"); return false; } bool CustomLogRecordExporter::Shutdown(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_ERROR("CustomLogRecordExporter::Shutdown(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_WARN("CustomLogRecordExporter::Shutdown(): YOUR CODE HERE"); return false; } diff --git a/examples/configuration/custom_log_record_processor.cc b/examples/configuration/custom_log_record_processor.cc index ff5a7ff744..1ce241d2c5 100644 --- a/examples/configuration/custom_log_record_processor.cc +++ b/examples/configuration/custom_log_record_processor.cc @@ -20,18 +20,18 @@ CustomLogRecordProcessor::MakeRecordable() noexcept void CustomLogRecordProcessor::OnEmit( std::unique_ptr &&span) noexcept { - OTEL_INTERNAL_LOG_ERROR("CustomLogRecordProcessor::OnEnd(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_WARN("CustomLogRecordProcessor::OnEnd(): YOUR CODE HERE"); auto unused = std::move(span); } bool CustomLogRecordProcessor::ForceFlush(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_ERROR("CustomLogRecordProcessor::ForceFlush(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_WARN("CustomLogRecordProcessor::ForceFlush(): YOUR CODE HERE"); return false; } bool CustomLogRecordProcessor::Shutdown(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_ERROR("CustomLogRecordProcessor::Shutdown(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_WARN("CustomLogRecordProcessor::Shutdown(): YOUR CODE HERE"); return false; } diff --git a/examples/configuration/custom_pull_metric_exporter.cc b/examples/configuration/custom_pull_metric_exporter.cc index 314f594044..2559c91c96 100644 --- a/examples/configuration/custom_pull_metric_exporter.cc +++ b/examples/configuration/custom_pull_metric_exporter.cc @@ -10,23 +10,23 @@ opentelemetry::sdk::metrics::AggregationTemporality CustomPullMetricExporter::GetAggregationTemporality( opentelemetry::sdk::metrics::InstrumentType /* instrument_type */) const noexcept { - OTEL_INTERNAL_LOG_ERROR("CustomPullMetricExporter::GetAggregationTemporality(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_WARN("CustomPullMetricExporter::GetAggregationTemporality(): YOUR CODE HERE"); return opentelemetry::sdk::metrics::AggregationTemporality::kCumulative; } bool CustomPullMetricExporter::OnForceFlush(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_ERROR("CustomPullMetricExporter::OnForceFlush(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_WARN("CustomPullMetricExporter::OnForceFlush(): YOUR CODE HERE"); return true; } bool CustomPullMetricExporter::OnShutDown(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_ERROR("CustomPullMetricExporter::OnShutDown(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_WARN("CustomPullMetricExporter::OnShutDown(): YOUR CODE HERE"); return true; } void CustomPullMetricExporter::OnInitialized() noexcept { - OTEL_INTERNAL_LOG_ERROR("CustomPullMetricExporter::OnInitialized(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_WARN("CustomPullMetricExporter::OnInitialized(): YOUR CODE HERE"); } diff --git a/examples/configuration/custom_push_metric_exporter.cc b/examples/configuration/custom_push_metric_exporter.cc index d30f17e505..b588ae7abd 100644 --- a/examples/configuration/custom_push_metric_exporter.cc +++ b/examples/configuration/custom_push_metric_exporter.cc @@ -10,7 +10,7 @@ opentelemetry::sdk::common::ExportResult CustomPushMetricExporter::Export( const opentelemetry::sdk::metrics::ResourceMetrics & /* data */) noexcept { - OTEL_INTERNAL_LOG_ERROR("CustomPushMetricExporter::Export(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_WARN("CustomPushMetricExporter::Export(): YOUR CODE HERE"); return opentelemetry::sdk::common::ExportResult::kSuccess; } @@ -18,18 +18,18 @@ opentelemetry::sdk::metrics::AggregationTemporality CustomPushMetricExporter::GetAggregationTemporality( opentelemetry::sdk::metrics::InstrumentType /* instrument_type */) const noexcept { - OTEL_INTERNAL_LOG_ERROR("CustomPushMetricExporter::GetAggregationTemporality(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_WARN("CustomPushMetricExporter::GetAggregationTemporality(): YOUR CODE HERE"); return opentelemetry::sdk::metrics::AggregationTemporality::kCumulative; } bool CustomPushMetricExporter::ForceFlush(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_ERROR("CustomPushMetricExporter::ForceFlush(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_WARN("CustomPushMetricExporter::ForceFlush(): YOUR CODE HERE"); return true; } bool CustomPushMetricExporter::Shutdown(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_ERROR("CustomPushMetricExporter::Shutdown(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_WARN("CustomPushMetricExporter::Shutdown(): YOUR CODE HERE"); return true; } diff --git a/examples/configuration/custom_span_exporter.cc b/examples/configuration/custom_span_exporter.cc index 1b870a1781..6478650a4e 100644 --- a/examples/configuration/custom_span_exporter.cc +++ b/examples/configuration/custom_span_exporter.cc @@ -19,18 +19,18 @@ opentelemetry::sdk::common::ExportResult CustomSpanExporter::Export( const opentelemetry::nostd::span> & /* spans */) noexcept { - OTEL_INTERNAL_LOG_ERROR("CustomSpanExporter::Export(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_WARN("CustomSpanExporter::Export(): YOUR CODE HERE"); return opentelemetry::sdk::common::ExportResult::kSuccess; } bool CustomSpanExporter::ForceFlush(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_ERROR("CustomSpanExporter::ForceFlush(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_WARN("CustomSpanExporter::ForceFlush(): YOUR CODE HERE"); return false; } bool CustomSpanExporter::Shutdown(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_ERROR("CustomSpanExporter::Shutdown(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_WARN("CustomSpanExporter::Shutdown(): YOUR CODE HERE"); return false; } diff --git a/examples/configuration/custom_span_processor.cc b/examples/configuration/custom_span_processor.cc index d575d8a462..b31265f177 100644 --- a/examples/configuration/custom_span_processor.cc +++ b/examples/configuration/custom_span_processor.cc @@ -21,24 +21,24 @@ void CustomSpanProcessor::OnStart( opentelemetry::sdk::trace::Recordable & /* span */, const opentelemetry::trace::SpanContext & /* parent_context */) noexcept { - OTEL_INTERNAL_LOG_ERROR("CustomSpanProcessor::OnStart(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_WARN("CustomSpanProcessor::OnStart(): YOUR CODE HERE"); } void CustomSpanProcessor::OnEnd( std::unique_ptr &&span) noexcept { - OTEL_INTERNAL_LOG_ERROR("CustomSpanProcessor::OnEnd(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_WARN("CustomSpanProcessor::OnEnd(): YOUR CODE HERE"); auto unused = std::move(span); } bool CustomSpanProcessor::ForceFlush(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_ERROR("CustomSpanProcessor::ForceFlush(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_WARN("CustomSpanProcessor::ForceFlush(): YOUR CODE HERE"); return false; } bool CustomSpanProcessor::Shutdown(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_ERROR("CustomSpanProcessor::Shutdown(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_WARN("CustomSpanProcessor::Shutdown(): YOUR CODE HERE"); return false; } diff --git a/examples/configuration/extensions.yaml b/examples/configuration/extensions.yaml index 1c7aa47313..4104490262 100644 --- a/examples/configuration/extensions.yaml +++ b/examples/configuration/extensions.yaml @@ -16,29 +16,14 @@ disabled: false # Environment variable: OTEL_PROPAGATORS propagator: # composite: [tracecontext, baggage, b3, b3multi, jaeger, xray, ottrace] - composite: tracecontext + composite: + - tracecontext: # Configure tracer provider. tracer_provider: # Configure span processors. processors: - # Configure a batch span processor. - - batch: - # Configure exporter. - # - # Environment variable: OTEL_TRACES_EXPORTER - exporter: - # Configure exporter to be zipkin. - zipkin: - # Configure endpoint. - # - # Environment variable: OTEL_EXPORTER_ZIPKIN_ENDPOINT - endpoint: http://localhost:9411/api/v2/spans - # Configure max time (in milliseconds) to wait for each export. - # - # Environment variable: OTEL_EXPORTER_ZIPKIN_TIMEOUT - timeout: 10000 - # Configure a simple span processor. + # Configure a simple span processor. - simple: # Configure exporter. exporter: @@ -58,6 +43,11 @@ tracer_provider: meter_provider: readers: + - periodic: + interval: 60000 + timeout: 30000 + exporter: + console: {} - pull: exporter: my_custom_pull_metric_exporter: @@ -66,6 +56,9 @@ meter_provider: exporter: my_custom_push_metric_exporter: comment: "This is a push metric exporter extension point, with properties." + producers: + - my_custom_metric_producer: + comment: "This is a metric producer extension point, with properties." logger_provider: processors: @@ -80,3 +73,9 @@ logger_provider: exporter: my_custom_log_record_exporter: comment: "This is a log record exporter extension point, with properties." + +resource: + detection/development: + detectors: + - my_custom_detector: + comment: "This is a resource detector extension point, with properties." diff --git a/examples/configuration/kitchen-sink.yaml b/examples/configuration/kitchen-sink.yaml index de8d00be68..cea9540010 100644 --- a/examples/configuration/kitchen-sink.yaml +++ b/examples/configuration/kitchen-sink.yaml @@ -859,7 +859,7 @@ resource: service: # Configure resource schema URL. # If omitted or null, no schema URL is used. - schema_url: https://opentelemetry.io/schemas/1.16.0 + schema_url: https://opentelemetry.io/schemas/1.43.0 # Configure instrumentation. # This type is in development and subject to breaking changes in minor versions. instrumentation/development: diff --git a/examples/configuration/main.cc b/examples/configuration/main.cc index 068ffdc619..9daf2639f9 100644 --- a/examples/configuration/main.cc +++ b/examples/configuration/main.cc @@ -14,6 +14,7 @@ #include "opentelemetry/sdk/configuration/configuration.h" #include "opentelemetry/sdk/configuration/configured_sdk.h" #include "opentelemetry/sdk/configuration/registry.h" +#include "opentelemetry/sdk/configuration/registry_factory.h" #include "opentelemetry/sdk/configuration/yaml_configuration_parser.h" #include "custom_log_record_exporter_builder.h" @@ -165,8 +166,8 @@ void InitOtel(const std::string &config_file) /* 1 - Create a registry */ - std::shared_ptr registry( - new opentelemetry::sdk::configuration::Registry); + std::shared_ptr registry = + opentelemetry::sdk::configuration::RegistryFactory::Create(); /* 2 - Populate the registry with the core components supported */ diff --git a/examples/configuration/sdk-default.yaml b/examples/configuration/sdk-default.yaml new file mode 100644 index 0000000000..c3b455e74d --- /dev/null +++ b/examples/configuration/sdk-default.yaml @@ -0,0 +1,185 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +# Exercises the built-in SDK component builders. +# +# The Registry provides one builder per SDK component type. Each builder constructs its component from the parsed configuration model. +# RegistryFactory::Create() pre-loads all the SDK default builders shown in this file. +# Call Set*Builder() on the Registry to swap in your own implementation before calling ConfiguredSdk::Create: +# +# auto registry = RegistryFactory::Create(); +# registry->SetBatchSpanProcessorBuilder(std::make_unique()); +# auto sdk = ConfiguredSdk::Create(registry, model); + +file_format: "1.0" +disabled: false +log_level: debug + +# Global attribute limits; signal-specific limits below override these. +attribute_limits: + attribute_value_length_limit: 4096 + attribute_count_limit: 128 + +# --- Logs --- +logger_provider: + processors: + - batch: # BatchLogRecordProcessorBuilder + schedule_delay: 1000 + export_timeout: 5000 + max_queue_size: 512 + max_export_batch_size: 128 + exporter: + console: # ConsoleLogRecordExporterBuilder + - simple: # SimpleLogRecordProcessorBuilder + exporter: + console: + limits: # overrides attribute_limits for log records + attribute_value_length_limit: 4096 + attribute_count_limit: 128 + logger_configurator/development: # LoggerConfiguratorBuilder + default_config: + enabled: true + minimum_severity: trace + trace_based: false + loggers: + - name: "io.opentelemetry.*" + config: + enabled: true + minimum_severity: trace + trace_based: false + - name: "noisy.*" + config: + enabled: false + +# --- Metrics --- +meter_provider: + readers: + - periodic: # PeriodicMetricReaderBuilder + interval: 10000 + timeout: 5000 + exporter: + console: # ConsolePushMetricExporterBuilder + cardinality_limits: + default: 2000 + counter: 1000 + histogram: 500 + views: + # explicit_bucket_histogram aggregation + - selector: + instrument_name: "my.histogram.*" + instrument_type: histogram + stream: + aggregation: + explicit_bucket_histogram: + boundaries: [0, 5, 10, 25, 50, 100, 250, 500, 1000] + record_min_max: true + aggregation_cardinality_limit: 500 + # base2_exponential_bucket_histogram aggregation + - selector: + instrument_name: "my.exp_histogram.*" + instrument_type: histogram + stream: + aggregation: + base2_exponential_bucket_histogram: + max_size: 160 + max_scale: 20 + record_min_max: true + # drop aggregation + - selector: + instrument_name: "my.dropped.*" + instrument_type: counter + stream: + aggregation: + drop: + # last_value aggregation + - selector: + instrument_name: "my.gauge.*" + instrument_type: observable_gauge + stream: + aggregation: + last_value: + # sum aggregation + - selector: + instrument_name: "my.sum.*" + instrument_type: up_down_counter + stream: + aggregation: + sum: + # default aggregation + - selector: + instrument_name: "my.default.*" + instrument_type: counter + stream: + aggregation: + default: + meter_configurator/development: # MeterConfiguratorBuilder + default_config: + enabled: true + meters: + - name: "io.opentelemetry.*" + config: + enabled: true + - name: "noisy.*" + config: + enabled: false + +# --- Propagators --- +propagator: + composite: + - tracecontext: + - baggage: + - b3: + - b3multi: + - jaeger: + +# --- Traces --- +tracer_provider: + processors: + - batch: # BatchSpanProcessorBuilder + schedule_delay: 1000 + export_timeout: 5000 + max_queue_size: 512 + max_export_batch_size: 128 + exporter: + console: # ConsoleSpanExporterBuilder + - simple: # SimpleSpanProcessorBuilder + exporter: + console: # ConsoleSpanExporterBuilder + limits: # overrides attribute_limits for spans + attribute_value_length_limit: 4096 + attribute_count_limit: 128 + event_count_limit: 128 + link_count_limit: 128 + event_attribute_count_limit: 128 + link_attribute_count_limit: 128 + sampler: + parent_based: # ParentBasedSamplerBuilder + root: + probability/development: # ProbabilitySamplerBuilder + ratio: 0.25 + remote_parent_sampled: + always_on: # AlwaysOnSamplerBuilder + remote_parent_not_sampled: + always_off: # AlwaysOffSamplerBuilder + local_parent_sampled: + always_on: # AlwaysOnSamplerBuilder + local_parent_not_sampled: + always_off: # AlwaysOffSamplerBuilder + tracer_configurator/development: # TracerConfiguratorBuilder + default_config: + enabled: false + tracers: + - name: "io.opentelemetry.*" + config: + enabled: true + - name: "noisy.*" + config: + enabled: false + +# Resource identifies this service instance. +resource: + attributes: + - name: service.name + value: sdk-builtin-test + attributes_list: "service.namespace=my-namespace,service.version=1.0.0" + schema_url: https://opentelemetry.io/schemas/1.43.0 From 10c5d510a3b1df90d589788d4eb78cf7321243ae Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Wed, 5 Aug 2026 17:22:16 -0400 Subject: [PATCH 11/20] fix clang-tidy and iwyu warnings --- sdk/src/configuration/sdk_builder.cc | 3 --- sdk/src/configuration/trace_builders.cc | 8 +++++--- sdk/test/configuration/configured_sdk_test.cc | 2 ++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/sdk/src/configuration/sdk_builder.cc b/sdk/src/configuration/sdk_builder.cc index cddb13cc75..c8935ee2f2 100644 --- a/sdk/src/configuration/sdk_builder.cc +++ b/sdk/src/configuration/sdk_builder.cc @@ -174,7 +174,6 @@ #include "opentelemetry/sdk/trace/tracer_provider.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/version.h" -#include "src/common/wildcard_match.h" #ifdef ENABLE_METRICS_EXEMPLAR_PREVIEW # include "opentelemetry/sdk/metrics/exemplar/filter_type.h" @@ -186,8 +185,6 @@ namespace sdk namespace configuration { -using common::WildcardMatch; - namespace { diff --git a/sdk/src/configuration/trace_builders.cc b/sdk/src/configuration/trace_builders.cc index 438b547972..980e883ba9 100644 --- a/sdk/src/configuration/trace_builders.cc +++ b/sdk/src/configuration/trace_builders.cc @@ -128,8 +128,9 @@ class DefaultJaegerRemoteSamplerBuilder : public JaegerRemoteSamplerBuilder public: std::unique_ptr Build( const JaegerRemoteSamplerConfiguration * /* model */, - std::unique_ptr && /* initial_sampler */) const override + std::unique_ptr &&initial_sampler) const override { + auto unused = std::move(initial_sampler); static const std::string die("JaegerRemoteSampler not supported"); throw UnsupportedException(die); } @@ -212,9 +213,10 @@ class DefaultComposableRuleBasedSamplerBuilder : public ComposableRuleBasedSampl public: std::unique_ptr Build( const ComposableRuleBasedSamplerConfiguration * /* model */, - std::vector> - && /* rule_samplers */) const override + std::vector> &&rule_samplers) + const override { + auto unused = std::move(rule_samplers); // TODO: implement once a concrete Predicate can be built from rule config static const std::string die("ComposableRuleBasedSampler not supported"); throw UnsupportedException(die); diff --git a/sdk/test/configuration/configured_sdk_test.cc b/sdk/test/configuration/configured_sdk_test.cc index ac4ea180a1..4cd82e20f1 100644 --- a/sdk/test/configuration/configured_sdk_test.cc +++ b/sdk/test/configuration/configured_sdk_test.cc @@ -18,6 +18,8 @@ #include "opentelemetry/trace/provider.h" #include "opentelemetry/sdk/common/global_log_handler.h" +#include "opentelemetry/sdk/configuration/batch_log_record_processor_builder.h" +#include "opentelemetry/sdk/configuration/batch_span_processor_builder.h" #include "opentelemetry/sdk/configuration/configuration.h" #include "opentelemetry/sdk/configuration/configured_sdk.h" #include "opentelemetry/sdk/configuration/extension_log_record_exporter_builder.h" From df70b9979c50c280cd56dc95590b6af7630ecd9a Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Wed, 5 Aug 2026 17:22:41 -0400 Subject: [PATCH 12/20] clean up composite sampler yaml --- examples/configuration/composite-sampler.yaml | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/examples/configuration/composite-sampler.yaml b/examples/configuration/composite-sampler.yaml index 7c6a1af3d3..a1b848d44a 100644 --- a/examples/configuration/composite-sampler.yaml +++ b/examples/configuration/composite-sampler.yaml @@ -1,23 +1,29 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -# composite-sampler.yaml exercises all composite/development sampler builder types. +# Exercises the composite/development sampler builder types. +# +# The Registry provides one builder per SDK component type. Each builder constructs its component from the parsed configuration model. +# RegistryFactory::Create() pre-loads all the SDK default builders shown in this file. +# Call Set*Builder() on the Registry to swap in your own implementation before calling ConfiguredSdk::Create: +# +# auto registry = RegistryFactory::Create(); +# registry->SetComposableRuleBasedSamplerBuilder(std::make_unique()); +# auto sdk = ConfiguredSdk::Create(registry, model); file_format: "1.0" log_level: info tracer_provider: processors: - - simple: + - simple: # SimpleSpanProcessorBuilder exporter: - console: + console: # ConsoleSpanExporterBuilder sampler: - # parent_based sampler - parent_based: + parent_based: # ParentBasedSamplerBuilder root: - # rule_based composable sampler composite/development: - rule_based: + rule_based: # ComposableRuleBasedSamplerBuilder rules: - attribute_values: key: http.method @@ -41,22 +47,18 @@ tracer_provider: - sampler: always_off: remote_parent_sampled: - # always_on composable sampler composite/development: - always_on: + always_on: # ComposableAlwaysOnSamplerBuilder remote_parent_not_sampled: - # always_off composable sampler composite/development: - always_off: + always_off: # ComposableAlwaysOffSamplerBuilder local_parent_sampled: - # probability composable sampler composite/development: - probability: + probability: # ComposableProbabilitySamplerBuilder ratio: 0.5 local_parent_not_sampled: - # parent_threshold composable sampler composite/development: - parent_threshold: + parent_threshold: # ComposableParentThresholdSamplerBuilder root: probability: ratio: 0.1 From bc9d3358fcefced794541cf142650fdf08022e48 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Wed, 5 Aug 2026 20:07:37 -0400 Subject: [PATCH 13/20] add changelog entry --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f584c3b765..c0043814e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -139,6 +139,13 @@ Increment the: Breaking changes: +* [CONFIGURATION] SDK default component builder libraries and example + [#4367](https://github.com/open-telemetry/opentelemetry-cpp/pull/4367) + * The declaritive configuration registry is now empty on construction and + the default SDK component builders are provided optionally through + the `opentelemetry-cpp::configuration_registry_factory` library and + the `opentelemetry::sdk::configuration::RegistryFactory::Create()` method. + * [BUILD] Install an explicit list of ext headers instead of the whole directory [#4327](https://github.com/open-telemetry/opentelemetry-cpp/pull/4327) From 6c4425a595639bfae132541adf8733015c914bf1 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Fri, 7 Aug 2026 11:02:41 -0400 Subject: [PATCH 14/20] [DO NOT REVIEW - this commit is to take the yaml file and example changes from #4374 and should be reviewed in that PR] --- ci/do_ci.sh | 7 +- examples/configuration/BUILD | 39 +- examples/configuration/CMakeLists.txt | 18 +- examples/configuration/composite-sampler.yaml | 64 --- .../custom_log_record_exporter.cc | 6 +- .../custom_log_record_processor.cc | 6 +- .../custom_pull_metric_exporter.cc | 8 +- .../custom_push_metric_exporter.cc | 8 +- .../configuration/custom_span_exporter.cc | 6 +- .../configuration/custom_span_processor.cc | 8 +- examples/configuration/extensions.yaml | 40 +- examples/configuration/kitchen-sink.yaml | 374 +++++++++++------- examples/configuration/main.cc | 5 +- 13 files changed, 282 insertions(+), 307 deletions(-) delete mode 100644 examples/configuration/composite-sampler.yaml diff --git a/ci/do_ci.sh b/ci/do_ci.sh index cc825c37f1..830ca4c998 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -626,9 +626,10 @@ elif [[ "$1" == "bazel.ubsan" ]]; then bazel $BAZEL_STARTUP_OPTIONS test --config=ubsan $BAZEL_TEST_OPTIONS_ASYNC //... exit 0 elif [[ "$1" == "bazel.tsan" ]]; then -# TODO - potential race condition in Civetweb server used by prometheus-cpp during shutdown -# https://github.com/civetweb/civetweb/issues/861, so removing prometheus from the test - bazel $BAZEL_STARTUP_OPTIONS test --config=tsan $BAZEL_TEST_OPTIONS_ASYNC -- //... -//exporters/prometheus/... +# Known intentional race in civetweb (used by prometheus-cpp) during shutdown +# https://github.com/civetweb/civetweb/issues/1184, so excluding targets that +# start the civetweb server from the test + bazel $BAZEL_STARTUP_OPTIONS test --config=tsan $BAZEL_TEST_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//examples/configuration:example_yaml_kitchen_sink exit 0 elif [[ "$1" == "bazel.valgrind" ]]; then bazel $BAZEL_STARTUP_OPTIONS build $BAZEL_OPTIONS_ASYNC //... diff --git a/examples/configuration/BUILD b/examples/configuration/BUILD index 06e181e956..0ce88da030 100644 --- a/examples/configuration/BUILD +++ b/examples/configuration/BUILD @@ -4,15 +4,15 @@ load("@rules_cc//cc:cc_test.bzl", "cc_test") cc_test( - name = "example_yaml", + name = "example_yaml_kitchen_sink", size = "medium", srcs = glob(["*.cc"]) + glob(["*.h"]), args = [ "--test", "--yaml", - "$(location sdk-default.yaml)", + "$(location kitchen-sink.yaml)", ], - data = ["sdk-default.yaml"], + data = ["kitchen-sink.yaml"], defines = [ "OTEL_HAVE_OTLP_HTTP", "OTEL_HAVE_OTLP_GRPC", @@ -42,38 +42,6 @@ cc_test( "//exporters/prometheus:prometheus_exporter_builder", "//sdk:headers", "//sdk/src/configuration", - "//sdk/src/configuration:configuration_registry_factory", - "//sdk/src/logs", - "//sdk/src/metrics", - "//sdk/src/trace", - "@com_google_googletest//:gtest_main", - ], -) - -cc_test( - name = "example_yaml_composite_sampler", - size = "medium", - srcs = glob(["*.cc"]) + glob(["*.h"]), - args = [ - "--test", - "--yaml", - "$(location composite-sampler.yaml)", - ], - data = ["composite-sampler.yaml"], - tags = [ - "test", - "yaml", - ], - deps = [ - "//api", - "//examples/common/logs_foo_library:common_logs_foo_library", - "//examples/common/metrics_foo_library:common_metrics_foo_library", - "//exporters/ostream:ostream_log_record_exporter_builder", - "//exporters/ostream:ostream_metric_exporter_builder", - "//exporters/ostream:ostream_span_exporter_builder", - "//sdk:headers", - "//sdk/src/configuration", - "//sdk/src/configuration:configuration_registry_factory", "//sdk/src/logs", "//sdk/src/metrics", "//sdk/src/trace", @@ -104,7 +72,6 @@ cc_test( "//exporters/ostream:ostream_span_exporter_builder", "//sdk:headers", "//sdk/src/configuration", - "//sdk/src/configuration:configuration_registry_factory", "//sdk/src/logs", "//sdk/src/metrics", "//sdk/src/trace", diff --git a/examples/configuration/CMakeLists.txt b/examples/configuration/CMakeLists.txt index c52f04ff5c..a5c31c1b55 100644 --- a/examples/configuration/CMakeLists.txt +++ b/examples/configuration/CMakeLists.txt @@ -69,27 +69,15 @@ if(DEFINED OPENTELEMETRY_BUILD_DLL) else() target_link_libraries( example_yaml - PRIVATE opentelemetry-cpp::configuration_registry_factory - opentelemetry-cpp::configuration opentelemetry-cpp::common + PRIVATE opentelemetry-cpp::configuration opentelemetry-cpp::common opentelemetry-cpp::trace opentelemetry-cpp::logs) endif() if(BUILD_TESTING) - add_test(NAME examples.example_yaml_sdk_default + add_test(NAME examples.example_yaml_kitchen_sink COMMAND $ --test --yaml - ${CMAKE_CURRENT_SOURCE_DIR}/sdk-default.yaml) - set_tests_properties(examples.example_yaml_sdk_default - PROPERTIES FAIL_REGULAR_EXPRESSION "\\[ERROR\\]") - - add_test(NAME examples.example_yaml_composite_sampler - COMMAND $ --test --yaml - ${CMAKE_CURRENT_SOURCE_DIR}/composite-sampler.yaml) - set_tests_properties(examples.example_yaml_composite_sampler - PROPERTIES FAIL_REGULAR_EXPRESSION "\\[ERROR\\]") - + ${CMAKE_CURRENT_SOURCE_DIR}/kitchen-sink.yaml) add_test(NAME examples.example_yaml_extensions COMMAND $ --test --yaml ${CMAKE_CURRENT_SOURCE_DIR}/extensions.yaml) - set_tests_properties(examples.example_yaml_extensions - PROPERTIES FAIL_REGULAR_EXPRESSION "\\[ERROR\\]") endif() diff --git a/examples/configuration/composite-sampler.yaml b/examples/configuration/composite-sampler.yaml deleted file mode 100644 index a1b848d44a..0000000000 --- a/examples/configuration/composite-sampler.yaml +++ /dev/null @@ -1,64 +0,0 @@ -# Copyright The OpenTelemetry Authors -# SPDX-License-Identifier: Apache-2.0 - -# Exercises the composite/development sampler builder types. -# -# The Registry provides one builder per SDK component type. Each builder constructs its component from the parsed configuration model. -# RegistryFactory::Create() pre-loads all the SDK default builders shown in this file. -# Call Set*Builder() on the Registry to swap in your own implementation before calling ConfiguredSdk::Create: -# -# auto registry = RegistryFactory::Create(); -# registry->SetComposableRuleBasedSamplerBuilder(std::make_unique()); -# auto sdk = ConfiguredSdk::Create(registry, model); - -file_format: "1.0" -log_level: info - -tracer_provider: - processors: - - simple: # SimpleSpanProcessorBuilder - exporter: - console: # ConsoleSpanExporterBuilder - sampler: - parent_based: # ParentBasedSamplerBuilder - root: - composite/development: - rule_based: # ComposableRuleBasedSamplerBuilder - rules: - - attribute_values: - key: http.method - values: - - GET - - POST - attribute_patterns: - key: http.url - included: - - .*/api/.* - excluded: - - .*/healthz - parent: - - remote - - local - span_kinds: - - server - - client - sampler: - always_on: - - sampler: - always_off: - remote_parent_sampled: - composite/development: - always_on: # ComposableAlwaysOnSamplerBuilder - remote_parent_not_sampled: - composite/development: - always_off: # ComposableAlwaysOffSamplerBuilder - local_parent_sampled: - composite/development: - probability: # ComposableProbabilitySamplerBuilder - ratio: 0.5 - local_parent_not_sampled: - composite/development: - parent_threshold: # ComposableParentThresholdSamplerBuilder - root: - probability: - ratio: 0.1 diff --git a/examples/configuration/custom_log_record_exporter.cc b/examples/configuration/custom_log_record_exporter.cc index 505cf98805..a69159153d 100644 --- a/examples/configuration/custom_log_record_exporter.cc +++ b/examples/configuration/custom_log_record_exporter.cc @@ -20,18 +20,18 @@ opentelemetry::sdk::common::ExportResult CustomLogRecordExporter::Export( const opentelemetry::nostd::span> & /* records */) noexcept { - OTEL_INTERNAL_LOG_WARN("CustomLogRecordExporter::Export(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_ERROR("CustomLogRecordExporter::Export(): YOUR CODE HERE"); return opentelemetry::sdk::common::ExportResult::kSuccess; } bool CustomLogRecordExporter::ForceFlush(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_WARN("CustomLogRecordExporter::ForceFlush(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_ERROR("CustomLogRecordExporter::ForceFlush(): YOUR CODE HERE"); return false; } bool CustomLogRecordExporter::Shutdown(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_WARN("CustomLogRecordExporter::Shutdown(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_ERROR("CustomLogRecordExporter::Shutdown(): YOUR CODE HERE"); return false; } diff --git a/examples/configuration/custom_log_record_processor.cc b/examples/configuration/custom_log_record_processor.cc index 1ce241d2c5..ff5a7ff744 100644 --- a/examples/configuration/custom_log_record_processor.cc +++ b/examples/configuration/custom_log_record_processor.cc @@ -20,18 +20,18 @@ CustomLogRecordProcessor::MakeRecordable() noexcept void CustomLogRecordProcessor::OnEmit( std::unique_ptr &&span) noexcept { - OTEL_INTERNAL_LOG_WARN("CustomLogRecordProcessor::OnEnd(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_ERROR("CustomLogRecordProcessor::OnEnd(): YOUR CODE HERE"); auto unused = std::move(span); } bool CustomLogRecordProcessor::ForceFlush(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_WARN("CustomLogRecordProcessor::ForceFlush(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_ERROR("CustomLogRecordProcessor::ForceFlush(): YOUR CODE HERE"); return false; } bool CustomLogRecordProcessor::Shutdown(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_WARN("CustomLogRecordProcessor::Shutdown(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_ERROR("CustomLogRecordProcessor::Shutdown(): YOUR CODE HERE"); return false; } diff --git a/examples/configuration/custom_pull_metric_exporter.cc b/examples/configuration/custom_pull_metric_exporter.cc index 2559c91c96..314f594044 100644 --- a/examples/configuration/custom_pull_metric_exporter.cc +++ b/examples/configuration/custom_pull_metric_exporter.cc @@ -10,23 +10,23 @@ opentelemetry::sdk::metrics::AggregationTemporality CustomPullMetricExporter::GetAggregationTemporality( opentelemetry::sdk::metrics::InstrumentType /* instrument_type */) const noexcept { - OTEL_INTERNAL_LOG_WARN("CustomPullMetricExporter::GetAggregationTemporality(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_ERROR("CustomPullMetricExporter::GetAggregationTemporality(): YOUR CODE HERE"); return opentelemetry::sdk::metrics::AggregationTemporality::kCumulative; } bool CustomPullMetricExporter::OnForceFlush(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_WARN("CustomPullMetricExporter::OnForceFlush(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_ERROR("CustomPullMetricExporter::OnForceFlush(): YOUR CODE HERE"); return true; } bool CustomPullMetricExporter::OnShutDown(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_WARN("CustomPullMetricExporter::OnShutDown(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_ERROR("CustomPullMetricExporter::OnShutDown(): YOUR CODE HERE"); return true; } void CustomPullMetricExporter::OnInitialized() noexcept { - OTEL_INTERNAL_LOG_WARN("CustomPullMetricExporter::OnInitialized(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_ERROR("CustomPullMetricExporter::OnInitialized(): YOUR CODE HERE"); } diff --git a/examples/configuration/custom_push_metric_exporter.cc b/examples/configuration/custom_push_metric_exporter.cc index b588ae7abd..d30f17e505 100644 --- a/examples/configuration/custom_push_metric_exporter.cc +++ b/examples/configuration/custom_push_metric_exporter.cc @@ -10,7 +10,7 @@ opentelemetry::sdk::common::ExportResult CustomPushMetricExporter::Export( const opentelemetry::sdk::metrics::ResourceMetrics & /* data */) noexcept { - OTEL_INTERNAL_LOG_WARN("CustomPushMetricExporter::Export(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_ERROR("CustomPushMetricExporter::Export(): YOUR CODE HERE"); return opentelemetry::sdk::common::ExportResult::kSuccess; } @@ -18,18 +18,18 @@ opentelemetry::sdk::metrics::AggregationTemporality CustomPushMetricExporter::GetAggregationTemporality( opentelemetry::sdk::metrics::InstrumentType /* instrument_type */) const noexcept { - OTEL_INTERNAL_LOG_WARN("CustomPushMetricExporter::GetAggregationTemporality(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_ERROR("CustomPushMetricExporter::GetAggregationTemporality(): YOUR CODE HERE"); return opentelemetry::sdk::metrics::AggregationTemporality::kCumulative; } bool CustomPushMetricExporter::ForceFlush(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_WARN("CustomPushMetricExporter::ForceFlush(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_ERROR("CustomPushMetricExporter::ForceFlush(): YOUR CODE HERE"); return true; } bool CustomPushMetricExporter::Shutdown(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_WARN("CustomPushMetricExporter::Shutdown(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_ERROR("CustomPushMetricExporter::Shutdown(): YOUR CODE HERE"); return true; } diff --git a/examples/configuration/custom_span_exporter.cc b/examples/configuration/custom_span_exporter.cc index 6478650a4e..1b870a1781 100644 --- a/examples/configuration/custom_span_exporter.cc +++ b/examples/configuration/custom_span_exporter.cc @@ -19,18 +19,18 @@ opentelemetry::sdk::common::ExportResult CustomSpanExporter::Export( const opentelemetry::nostd::span> & /* spans */) noexcept { - OTEL_INTERNAL_LOG_WARN("CustomSpanExporter::Export(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_ERROR("CustomSpanExporter::Export(): YOUR CODE HERE"); return opentelemetry::sdk::common::ExportResult::kSuccess; } bool CustomSpanExporter::ForceFlush(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_WARN("CustomSpanExporter::ForceFlush(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_ERROR("CustomSpanExporter::ForceFlush(): YOUR CODE HERE"); return false; } bool CustomSpanExporter::Shutdown(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_WARN("CustomSpanExporter::Shutdown(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_ERROR("CustomSpanExporter::Shutdown(): YOUR CODE HERE"); return false; } diff --git a/examples/configuration/custom_span_processor.cc b/examples/configuration/custom_span_processor.cc index b31265f177..d575d8a462 100644 --- a/examples/configuration/custom_span_processor.cc +++ b/examples/configuration/custom_span_processor.cc @@ -21,24 +21,24 @@ void CustomSpanProcessor::OnStart( opentelemetry::sdk::trace::Recordable & /* span */, const opentelemetry::trace::SpanContext & /* parent_context */) noexcept { - OTEL_INTERNAL_LOG_WARN("CustomSpanProcessor::OnStart(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_ERROR("CustomSpanProcessor::OnStart(): YOUR CODE HERE"); } void CustomSpanProcessor::OnEnd( std::unique_ptr &&span) noexcept { - OTEL_INTERNAL_LOG_WARN("CustomSpanProcessor::OnEnd(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_ERROR("CustomSpanProcessor::OnEnd(): YOUR CODE HERE"); auto unused = std::move(span); } bool CustomSpanProcessor::ForceFlush(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_WARN("CustomSpanProcessor::ForceFlush(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_ERROR("CustomSpanProcessor::ForceFlush(): YOUR CODE HERE"); return false; } bool CustomSpanProcessor::Shutdown(std::chrono::microseconds /* timeout */) noexcept { - OTEL_INTERNAL_LOG_WARN("CustomSpanProcessor::Shutdown(): YOUR CODE HERE"); + OTEL_INTERNAL_LOG_ERROR("CustomSpanProcessor::Shutdown(): YOUR CODE HERE"); return false; } diff --git a/examples/configuration/extensions.yaml b/examples/configuration/extensions.yaml index 4104490262..7f75513e54 100644 --- a/examples/configuration/extensions.yaml +++ b/examples/configuration/extensions.yaml @@ -1,21 +1,17 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -# The file format version -file_format: "1.0" +# extensions.yaml demonstrates the extension points in the configuration model. +# Each my_custom_* key maps to a builder that can be registered via Registry::SetExtension*Builder (see main.cc). +file_format: "1.1" -# Configure if the SDK is disabled or not. This is not required to be provided -# to ensure the SDK isn't disabled, the default value when this is not provided -# is for the SDK to be enabled. -# -# Environment variable: OTEL_SDK_DISABLED +# Configure if the SDK is disabled or not. +# If omitted or null, false is used. disabled: false # Configure text map context propagators. -# -# Environment variable: OTEL_PROPAGATORS +# If omitted, a noop propagator is used. propagator: - # composite: [tracecontext, baggage, b3, b3multi, jaeger, xray, ottrace] composite: - tracecontext: @@ -23,59 +19,61 @@ propagator: tracer_provider: # Configure span processors. processors: - # Configure a simple span processor. + # Configure a simple span processor. - simple: - # Configure exporter. exporter: - # Configure exporter to be console. - console: {} + console: + # Registry::SetExtensionSpanProcessorBuilder, see custom_span_processor.cc. - my_custom_span_processor: comment: "This is a span processor extension point, with properties." - batch: exporter: + # Registry::SetExtensionSpanExporterBuilder, see custom_span_exporter.cc. my_custom_span_exporter: comment: "This is a span exporter extension point, with properties." # Configure the sampler. sampler: + # Registry::SetExtensionSamplerBuilder, see custom_sampler.cc. my_custom_sampler: comment: "This is a sampler extension point, with properties." meter_provider: readers: - periodic: - interval: 60000 - timeout: 30000 exporter: - console: {} + console: - pull: exporter: + # Registry::SetExtensionPullMetricExporterBuilder, see custom_pull_metric_exporter.cc. my_custom_pull_metric_exporter: comment: "This is a pull metric exporter extension point, with properties." - periodic: exporter: + # Registry::SetExtensionPushMetricExporterBuilder, see custom_push_metric_exporter.cc. my_custom_push_metric_exporter: comment: "This is a push metric exporter extension point, with properties." producers: + # Registry::SetExtensionMetricProducerBuilder. No example implementation in this directory. - my_custom_metric_producer: comment: "This is a metric producer extension point, with properties." logger_provider: processors: - simple: - # Configure exporter. exporter: - # Configure exporter to be console. - console: {} + console: + # Registry::SetExtensionLogRecordProcessorBuilder, see custom_log_record_processor.cc. - my_custom_log_record_processor: comment: "This is a log record processor extension point, with properties." - batch: exporter: + # Registry::SetExtensionLogRecordExporterBuilder, see custom_log_record_exporter.cc. my_custom_log_record_exporter: comment: "This is a log record exporter extension point, with properties." - resource: detection/development: detectors: + # Registry::SetExtensionResourceDetectorBuilder. No example implementation in this directory. - my_custom_detector: comment: "This is a resource detector extension point, with properties." diff --git a/examples/configuration/kitchen-sink.yaml b/examples/configuration/kitchen-sink.yaml index cea9540010..1d9117ab86 100644 --- a/examples/configuration/kitchen-sink.yaml +++ b/examples/configuration/kitchen-sink.yaml @@ -11,7 +11,7 @@ # The file format version. # The yaml format is documented at # https://github.com/open-telemetry/opentelemetry-configuration/tree/main/schema -file_format: "1.0-rc.1" +file_format: "1.1" # Configure if the SDK is disabled or not. # If omitted or null, false is used. disabled: false @@ -54,18 +54,20 @@ logger_provider: # Configure exporter to be OTLP with HTTP transport. otlp_http: endpoint: http://localhost:4318/v1/logs - # Configure certificate used to verify a server's TLS credentials. - # Absolute path to certificate file in PEM format. - # If omitted or null, system default certificate verification is used for secure connections. - certificate_file: /app/cert.pem - # Configure mTLS private client key. - # Absolute path to client key file in PEM format. If set, .client_certificate must also be set. - # If omitted or null, mTLS is not used. - client_key_file: /app/cert.pem - # Configure mTLS client certificate. - # Absolute path to client certificate file in PEM format. If set, .client_key must also be set. - # If omitted or null, mTLS is not used. - client_certificate_file: /app/cert.pem + # Configure TLS settings. + tls: + # Configure certificate used to verify a server's TLS credentials. + # Absolute path to certificate file in PEM format. + # If omitted or null, system default certificate verification is used for secure connections. + ca_file: /app/cert.pem + # Configure mTLS private client key. + # Absolute path to client key file in PEM format. If set, .cert_file must also be set. + # If omitted or null, mTLS is not used. + key_file: /app/cert.pem + # Configure mTLS client certificate. + # Absolute path to client certificate file in PEM format. If set, .key_file must also be set. + # If omitted or null, mTLS is not used. + cert_file: /app/cert.pem # Configure headers. Entries have higher priority than entries from .headers_list. # If an entry's .value is null, the entry is ignored. headers: @@ -96,18 +98,24 @@ logger_provider: # Configure endpoint. # If omitted or null, http://localhost:4317 is used. endpoint: http://localhost:4317 - # Configure certificate used to verify a server's TLS credentials. - # Absolute path to certificate file in PEM format. - # If omitted or null, system default certificate verification is used for secure connections. - certificate_file: /app/cert.pem - # Configure mTLS private client key. - # Absolute path to client key file in PEM format. If set, .client_certificate must also be set. - # If omitted or null, mTLS is not used. - client_key_file: /app/cert.pem - # Configure mTLS client certificate. - # Absolute path to client certificate file in PEM format. If set, .client_key must also be set. - # If omitted or null, mTLS is not used. - client_certificate_file: /app/cert.pem + # Configure TLS settings. + tls: + # Configure certificate used to verify a server's TLS credentials. + # Absolute path to certificate file in PEM format. + # If omitted or null, system default certificate verification is used for secure connections. + ca_file: /app/cert.pem + # Configure mTLS private client key. + # Absolute path to client key file in PEM format. If set, .cert_file must also be set. + # If omitted or null, mTLS is not used. + key_file: /app/cert.pem + # Configure mTLS client certificate. + # Absolute path to client certificate file in PEM format. If set, .key_file must also be set. + # If omitted or null, mTLS is not used. + cert_file: /app/cert.pem + # Configure client transport security for the exporter's connection. + # Only applicable when .endpoint is provided without http or https scheme. Implementations may choose to ignore .insecure. + # If omitted or null, false is used. + insecure: false # Configure headers. Entries have higher priority than entries from .headers_list. # If an entry's .value is null, the entry is ignored. headers: @@ -125,10 +133,6 @@ logger_provider: # Value must be non-negative. A value of 0 indicates no limit (infinity). # If omitted or null, 10000 is used. timeout: 10000 - # Configure client transport security for the exporter's connection. - # Only applicable when .endpoint is provided without http or https scheme. Implementations may choose to ignore .insecure. - # If omitted or null, false is used. - insecure: false - # Configure a batch log record processor. batch: # Configure exporter. @@ -157,6 +161,9 @@ logger_provider: exporter: # Configure exporter to be console. console: + # Configure an event to span event bridge log record processor. + # This type is in development and subject to breaking changes in minor versions. + #- event_to_span_event_bridge/development: # Configure log record limits. See also attribute_limits. limits: # Configure max attribute value size. Overrides .attribute_limits.attribute_value_length_limit. @@ -173,7 +180,13 @@ logger_provider: # Configure the default logger config used there is no matching entry in .logger_configurator/development.loggers. default_config: # Configure if the logger is enabled or not. - disabled: true + enabled: false + # Configure minimum severity. Values include: trace, trace2, trace3, trace4, debug, debug2, debug3, debug4, info, info2, info3, info4, warn, warn2, warn3, warn4, error, error2, error3, error4, fatal, fatal2, fatal3, fatal4. + # If omitted, severity filtering is not applied. + minimum_severity: warn + # Configure if trace-based filtering is enabled. A boolean indication of whether the logger should drop log records associated with an unsampled trace. + # If omitted or null, false is used. + trace_based: false # Configure loggers. loggers: - # Configure logger names to match, evaluated as follows: @@ -184,7 +197,19 @@ logger_provider: # The logger config. config: # Configure if the logger is enabled or not. - disabled: false + enabled: true + - name: com.example.foo.* + config: + enabled: true + # Configure minimum severity. Values include: trace, trace2, trace3, trace4, debug, debug2, debug3, debug4, info, info2, info3, info4, warn, warn2, warn3, warn4, error, error2, error3, error4, fatal, fatal2, fatal3, fatal4. + # If omitted, severity filtering is not applied. + minimum_severity: info + # Configure if trace-based filtering is enabled. A boolean indication of whether the logger should drop log records associated with an unsampled trace. + # If omitted or null, false is used. + trace_based: true + - name: noisy.* + config: + enabled: false # Configure meter provider. # If omitted, a noop meter provider is used. meter_provider: @@ -202,18 +227,15 @@ meter_provider: host: localhost # Configure port. # If omitted or null, 9464 is used. - port: 9464 - # Configure Prometheus Exporter to produce metrics without a unit suffix or UNIT metadata. - # If omitted or null, false is used. - without_units: false - # Configure Prometheus Exporter to produce metrics without a type suffix. - # If omitted or null, false is used. - without_type_suffix: false - # Configure Prometheus Exporter to produce metrics without a scope info metric. - # If omitted or null, false is used. - without_scope_info: false - # Configure Prometheus Exporter to add resource attributes as metrics attributes. - with_resource_constant_labels: + port: 19464 + # Configure if scope info metric is produced. + # If omitted or null, true is used. + scope_info_enabled: true + # Configure if target info metric is produced. + # If omitted or null, true is used. + target_info_enabled/development: true + # Configure resource attributes to add as metric attributes. + resource_constant_labels: # Configure resource attributes to be included. # Attribute keys from resources are evaluated to match as follows: # * If the value of the attribute key exactly matches. @@ -221,7 +243,7 @@ meter_provider: # If omitted, no resource attributes are included. included: - "service*" - # Configure resource attributes to be excluded. Applies after .with_resource_constant_labels.included (i.e. excluded has higher priority than included). + # Configure resource attributes to be excluded. Applies after .resource_constant_labels.included (i.e. excluded has higher priority than included). # Attribute keys from resources are evaluated to match as follows: # * If the value of the attribute key exactly matches. # * If the value of the attribute key matches the wildcard pattern, where '?' matches any single character and '*' matches any number of characters including none. @@ -269,6 +291,9 @@ meter_provider: # Value must be non-negative. A value of 0 indicates no limit (infinity). # If omitted or null, 30000 is used. timeout: 30000 + # Configure maximum export batch size. Added in schema 1.1.0. + # If omitted or null, no limit is used. + max_export_batch_size/development: 512 # Configure exporter. exporter: # Configure exporter to be OTLP with HTTP transport. @@ -276,18 +301,20 @@ meter_provider: # Configure endpoint, including the metric specific path. # If omitted or null, http://localhost:4318/v1/metrics is used. endpoint: http://localhost:4318/v1/metrics - # Configure certificate used to verify a server's TLS credentials. - # Absolute path to certificate file in PEM format. - # If omitted or null, system default certificate verification is used for secure connections. - certificate_file: /app/cert.pem - # Configure mTLS private client key. - # Absolute path to client key file in PEM format. If set, .client_certificate must also be set. - # If omitted or null, mTLS is not used. - client_key_file: /app/cert.pem - # Configure mTLS client certificate. - # Absolute path to client certificate file in PEM format. If set, .client_key must also be set. - # If omitted or null, mTLS is not used. - client_certificate_file: /app/cert.pem + # Configure TLS settings. + tls: + # Configure certificate used to verify a server's TLS credentials. + # Absolute path to certificate file in PEM format. + # If omitted or null, system default certificate verification is used for secure connections. + ca_file: /app/cert.pem + # Configure mTLS private client key. + # Absolute path to client key file in PEM format. If set, .cert_file must also be set. + # If omitted or null, mTLS is not used. + key_file: /app/cert.pem + # Configure mTLS client certificate. + # Absolute path to client certificate file in PEM format. If set, .key_file must also be set. + # If omitted or null, mTLS is not used. + cert_file: /app/cert.pem # Configure headers. Entries have higher priority than entries from .headers_list. # If an entry's .value is null, the entry is ignored. headers: @@ -357,18 +384,24 @@ meter_provider: # Configure endpoint. # If omitted or null, http://localhost:4317 is used. endpoint: http://localhost:4317 - # Configure certificate used to verify a server's TLS credentials. - # Absolute path to certificate file in PEM format. - # If omitted or null, system default certificate verification is used for secure connections. - certificate_file: /app/cert.pem - # Configure mTLS private client key. - # Absolute path to client key file in PEM format. If set, .client_certificate must also be set. - # If omitted or null, mTLS is not used. - client_key_file: /app/cert.pem - # Configure mTLS client certificate. - # Absolute path to client certificate file in PEM format. If set, .client_key must also be set. - # If omitted or null, mTLS is not used. - client_certificate_file: /app/cert.pem + # Configure TLS settings. + tls: + # Configure certificate used to verify a server's TLS credentials. + # Absolute path to certificate file in PEM format. + # If omitted or null, system default certificate verification is used for secure connections. + ca_file: /app/cert.pem + # Configure mTLS private client key. + # Absolute path to client key file in PEM format. If set, .cert_file must also be set. + # If omitted or null, mTLS is not used. + key_file: /app/cert.pem + # Configure mTLS client certificate. + # Absolute path to client certificate file in PEM format. If set, .key_file must also be set. + # If omitted or null, mTLS is not used. + cert_file: /app/cert.pem + # Configure client transport security for the exporter's connection. + # Only applicable when .endpoint is provided without http or https scheme. Implementations may choose to ignore .insecure. + # If omitted or null, false is used. + insecure: false # Configure headers. Entries have higher priority than entries from .headers_list. # If an entry's .value is null, the entry is ignored. headers: @@ -386,10 +419,6 @@ meter_provider: # Value must be non-negative. A value of 0 indicates no limit (infinity). # If omitted or null, 10000 is used. timeout: 10000 - # Configure client transport security for the exporter's connection. - # Only applicable when .endpoint is provided without http or https scheme. Implementations may choose to ignore .insecure. - # If omitted or null, false is used. - insecure: false # Configure temporality preference. # Values include: cumulative, delta, low_memory. For behavior of values, see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk_exporters/otlp.md. # If omitted or null, cumulative is used. @@ -524,7 +553,7 @@ meter_provider: # Configure the default meter config used there is no matching entry in .meter_configurator/development.meters. default_config: # Configure if the meter is enabled or not. - disabled: true + enabled: false # Configure meters. meters: - # Configure meter names to match, evaluated as follows: @@ -535,12 +564,12 @@ meter_provider: # The meter config. config: # Configure if the meter is enabled or not. - disabled: false + enabled: true # Configure text map context propagators. # If omitted, a noop propagator is used. propagator: # Configure the propagators in the composite text map propagator. Entries from .composite_list are appended to the list here with duplicates filtered out. - # Built-in propagator keys include: tracecontext, baggage, b3, b3multi, jaeger, ottrace. Known third party keys include: xray. + # Built-in propagator keys include: tracecontext, baggage, b3, b3multi. Known third party keys include: xray. # If the resolved list of propagators (from .composite and .composite_list) is empty, a noop propagator is used. composite: - # Include the w3c trace context propagator. @@ -560,7 +589,7 @@ propagator: # Configure the propagators in the composite text map propagator. Entries are appended to .composite with duplicates filtered out. # The value is a comma separated list of propagator identifiers matching the format of OTEL_PROPAGATORS. See https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md#general-sdk-configuration for details. - # Built-in propagator identifiers include: tracecontext, baggage, b3, b3multi, jaeger, ottrace. Known third party identifiers include: xray. + # Built-in propagator identifiers include: tracecontext, baggage, b3, b3multi. Known third party identifiers include: xray. # If the resolved list of propagators (from .composite and .composite_list) is empty, a noop propagator is used. # composite_list: "tracecontext,baggage,b3,b3multi,jaeger,ottrace,xray" @@ -595,18 +624,20 @@ tracer_provider: # Configure endpoint, including the trace specific path. # If omitted or null, http://localhost:4318/v1/traces is used. endpoint: http://localhost:4318/v1/traces - # Configure certificate used to verify a server's TLS credentials. - # Absolute path to certificate file in PEM format. - # If omitted or null, system default certificate verification is used for secure connections. - certificate_file: /app/cert.pem - # Configure mTLS private client key. - # Absolute path to client key file in PEM format. If set, .client_certificate must also be set. - # If omitted or null, mTLS is not used. - client_key_file: /app/cert.pem - # Configure mTLS client certificate. - # Absolute path to client certificate file in PEM format. If set, .client_key must also be set. - # If omitted or null, mTLS is not used. - client_certificate_file: /app/cert.pem + # Configure TLS settings. + tls: + # Configure certificate used to verify a server's TLS credentials. + # Absolute path to certificate file in PEM format. + # If omitted or null, system default certificate verification is used for secure connections. + ca_file: /app/cert.pem + # Configure mTLS private client key. + # Absolute path to client key file in PEM format. If set, .cert_file must also be set. + # If omitted or null, mTLS is not used. + key_file: /app/cert.pem + # Configure mTLS client certificate. + # Absolute path to client certificate file in PEM format. If set, .key_file must also be set. + # If omitted or null, mTLS is not used. + cert_file: /app/cert.pem # Configure headers. Entries have higher priority than entries from .headers_list. # If an entry's .value is null, the entry is ignored. headers: @@ -637,18 +668,24 @@ tracer_provider: # Configure endpoint. # If omitted or null, http://localhost:4317 is used. endpoint: http://localhost:4317 - # Configure certificate used to verify a server's TLS credentials. - # Absolute path to certificate file in PEM format. - # If omitted or null, system default certificate verification is used for secure connections. - certificate_file: /app/cert.pem - # Configure mTLS private client key. - # Absolute path to client key file in PEM format. If set, .client_certificate must also be set. - # If omitted or null, mTLS is not used. - client_key_file: /app/cert.pem - # Configure mTLS client certificate. - # Absolute path to client certificate file in PEM format. If set, .client_key must also be set. - # If omitted or null, mTLS is not used. - client_certificate_file: /app/cert.pem + # Configure TLS settings. + tls: + # Configure certificate used to verify a server's TLS credentials. + # Absolute path to certificate file in PEM format. + # If omitted or null, system default certificate verification is used for secure connections. + ca_file: /app/cert.pem + # Configure mTLS private client key. + # Absolute path to client key file in PEM format. If set, .cert_file must also be set. + # If omitted or null, mTLS is not used. + key_file: /app/cert.pem + # Configure mTLS client certificate. + # Absolute path to client certificate file in PEM format. If set, .key_file must also be set. + # If omitted or null, mTLS is not used. + cert_file: /app/cert.pem + # Configure client transport security for the exporter's connection. + # Only applicable when .endpoint is provided without http or https scheme. Implementations may choose to ignore .insecure. + # If omitted or null, false is used. + insecure: false # Configure headers. Entries have higher priority than entries from .headers_list. # If an entry's .value is null, the entry is ignored. headers: @@ -666,10 +703,6 @@ tracer_provider: # Value must be non-negative. A value of 0 indicates no limit (infinity). # If omitted or null, 10000 is used. timeout: 10000 - # Configure client transport security for the exporter's connection. - # Only applicable when .endpoint is provided without http or https scheme. Implementations may choose to ignore .insecure. - # If omitted or null, false is used. - insecure: false - # Configure a batch span processor. batch: # Configure exporter. @@ -692,19 +725,6 @@ tracer_provider: # Values include stdout, or scheme+destination. For example: file:///path/to/file.jsonl. # If omitted or null, stdout is used. output_stream: stdout - - # Configure a batch span processor. - batch: - # Configure exporter. - exporter: - # Configure exporter to be zipkin. - zipkin: - # Configure endpoint. - # If omitted or null, http://localhost:9411/api/v2/spans is used. - endpoint: http://localhost:9411/api/v2/spans - # Configure max time (in milliseconds) to wait for each export. - # Value must be non-negative. A value of 0 indicates indefinite. - # If omitted or null, 10000 is used. - timeout: 10000 - # Configure a simple span processor. simple: # Configure exporter. @@ -737,19 +757,86 @@ tracer_provider: # Value must be non-negative. # If omitted or null, 128 is used. link_attribute_count_limit: 128 + # Configure the trace and span ID generator. + # If omitted, RandomIdGenerator is used. + id_generator: + # Use the built-in random ID generator. + random: # Configure the sampler. # If omitted, parent based sampler with a root of always_on is used. sampler: - # Configure sampler to be parent_based. + # parent_based honors upstream sampling decisions; the root sampler decides new traces. parent_based: - # Configure root sampler. + # Configure root sampler (applies when there is no parent span). # If omitted or null, always_on is used. root: - # Configure sampler to be trace_id_ratio_based. - trace_id_ratio_based: - # Configure trace_id_ratio. - # If omitted or null, 1.0 is used. - ratio: 0.0001 + # Configure sampler to be composite. + # This type is in development and subject to breaking changes in minor versions. + composite/development: + # Configure sampler to be rule_based. + # Rules are evaluated in order; the first matching rule's sampler is applied. + # Each rule may specify multiple conditions; all conditions must match for the rule to apply. + # If no conditions are specified, the rule matches all spans that reach it. + # If no rules match, the span is not sampled. + rule_based: + rules: + - # span_kinds: if the span's kind matches any listed value, the condition matches. If omitted, ignore. + # Values include: client, consumer, internal, producer, server. + span_kinds: + - internal + sampler: + # Configure sampler to be always_on. + always_on: + - # attribute_patterns: match a single attribute's value against wildcard patterns. + # '?' matches any single character, '*' matches any number of characters including none. Matching is case-sensitive. + # Non-string attributes use their string representation (e.g., '4*' matches http.response.status_code 400-499). + # For array attributes, if any item matches, it is considered a match. + attribute_patterns: + key: http.url + # included: value patterns to include. If omitted, all values are included. + included: + - .*/health* + # excluded: value patterns to exclude. Applies after included; excluded has higher priority than included. + excluded: + - .*/healthz/live + sampler: + # Configure sampler to be always_off. + always_off: + - # attribute_values: match a single attribute against exact string values. + # Non-string attributes use their string representation (e.g., "404" matches http.response.status_code 404). + # For array attributes, if any item matches, it is considered a match. + attribute_values: + key: http.response.status_code + # If the attribute's value matches any of these, the condition matches. + values: + - "500" + - "503" + sampler: + # Configure sampler to be always_on. + always_on: + - span_kinds: + - server + - consumer + # parent: match by parent span type. Values include: local, none (trace root), remote. If omitted, ignore. + parent: + - none + sampler: + # Configure sampler to be parent_threshold. + parent_threshold: + # Sampler to use when there is no parent. + root: + # Configure sampler to be ratio-based probability sampling using W3C Trace Context Level 2 randomness features. + probability: + # Configure sampling ratio. Value must be in range [0.0, 1.0]. + # If omitted or null, 1.0 is used. + ratio: 0.25 + - # No conditions: matches all spans that reach this rule (catch-all). + sampler: + # Configure sampler to be ratio-based probability sampling using W3C Trace Context Level 2 randomness features. + probability: + # Configure sampling ratio. Value must be in range [0.0, 1.0]. + # If omitted or null, 1.0 is used. + ratio: 0.01 # Configure remote_parent_sampled sampler. # If omitted or null, always_on is used. remote_parent_sampled: @@ -758,25 +845,33 @@ tracer_provider: # Configure remote_parent_not_sampled sampler. # If omitted or null, always_off is used. remote_parent_not_sampled: - # Configure sampler to be always_off. - always_off: + # trace_id_ratio_based uses trace ID hash for consistent cross-service sampling. + # Note: The trace_id_ratio_based sampler is deprecated in favor of the probability sampler + trace_id_ratio_based: + # Configure sampling ratio. Value must be in range [0.0, 1.0]. + # If omitted or null, 1.0 is used. + ratio: 0.001 # Configure local_parent_sampled sampler. # If omitted or null, always_on is used. local_parent_sampled: - # Configure sampler to be always_on. - always_on: + # Configure sampler to be always_off. + always_off: # Configure local_parent_not_sampled sampler. # If omitted or null, always_off is used. local_parent_not_sampled: - # Configure sampler to be always_off. - always_off: + # probability/development: ratio-based probability sampling using W3C Trace Context Level 2 randomness features. + probability/development: + # Configure sampling ratio. Value must be in range [0.0, 1.0]. + # If omitted or null, 1.0 is used. + ratio: 0.001 + # Configure tracers. # This type is in development and subject to breaking changes in minor versions. tracer_configurator/development: # Configure the default tracer config used there is no matching entry in .tracer_configurator/development.tracers. default_config: # Configure if the tracer is enabled or not. - disabled: true + enabled: false # Configure tracers. tracers: - # Configure tracer names to match, evaluated as follows: @@ -787,7 +882,7 @@ tracer_provider: # The tracer config. config: # Configure if the tracer is enabled or not. - disabled: false + enabled: true # Configure resource for all signals. # If omitted, the default resource is used. resource: @@ -857,26 +952,17 @@ resource: process: - # Enable the service detector, which populates service.name based on the OTEL_SERVICE_NAME environment variable and service.instance.id. service: + - # Enable an extension resource detector registered by name. + my_custom_detector: # Configure resource schema URL. # If omitted or null, no schema URL is used. - schema_url: https://opentelemetry.io/schemas/1.43.0 + schema_url: https://opentelemetry.io/schemas/1.16.0 # Configure instrumentation. # This type is in development and subject to breaking changes in minor versions. instrumentation/development: # Configure general SemConv options that may apply to multiple languages and instrumentations. # Instrumenation may merge general config options with the language specific configuration at .instrumentation.. general: - # Configure instrumentations following the peer semantic conventions. - # See peer semantic conventions: https://opentelemetry.io/docs/specs/semconv/attributes-registry/peer/ - peer: - # Configure the service mapping for instrumentations following peer.service semantic conventions. - # Each entry is a key value pair where "peer" defines the IP address and "service" defines the corresponding logical name of the service. - # See peer.service semantic conventions: https://opentelemetry.io/docs/specs/semconv/general/attributes/#general-remote-service-attributes - service_mapping: - - peer: 1.2.3.4 - service: FooService - - peer: 2.3.4.5 - service: BarService # Configure instrumentations following the http semantic conventions. # See http semantic conventions: https://opentelemetry.io/docs/specs/semconv/http/ http: diff --git a/examples/configuration/main.cc b/examples/configuration/main.cc index f24f1d26c5..c09a39a7b6 100644 --- a/examples/configuration/main.cc +++ b/examples/configuration/main.cc @@ -14,7 +14,6 @@ #include "opentelemetry/sdk/configuration/configuration.h" #include "opentelemetry/sdk/configuration/configured_sdk.h" #include "opentelemetry/sdk/configuration/registry.h" -#include "opentelemetry/sdk/configuration/registry_factory.h" #include "opentelemetry/sdk/configuration/yaml_configuration_parser.h" #include "custom_log_record_exporter_builder.h" @@ -166,8 +165,8 @@ void InitOtel(const std::string &config_file) /* 1 - Create a registry */ - std::shared_ptr registry = - opentelemetry::sdk::configuration::RegistryFactory::Create(); + std::shared_ptr registry( + new opentelemetry::sdk::configuration::Registry); /* 2 - Populate the registry with the core components supported */ From 69b55ec789a4faa12b7271b108a3e3fb0dbc652d Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Fri, 7 Aug 2026 11:03:41 -0400 Subject: [PATCH 15/20] update the configuration example to use the registry factory --- examples/configuration/BUILD | 2 ++ examples/configuration/CMakeLists.txt | 3 ++- examples/configuration/main.cc | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/configuration/BUILD b/examples/configuration/BUILD index 0ce88da030..49a672796f 100644 --- a/examples/configuration/BUILD +++ b/examples/configuration/BUILD @@ -42,6 +42,7 @@ cc_test( "//exporters/prometheus:prometheus_exporter_builder", "//sdk:headers", "//sdk/src/configuration", + "//sdk/src/configuration:configuration_registry_factory", "//sdk/src/logs", "//sdk/src/metrics", "//sdk/src/trace", @@ -72,6 +73,7 @@ cc_test( "//exporters/ostream:ostream_span_exporter_builder", "//sdk:headers", "//sdk/src/configuration", + "//sdk/src/configuration:configuration_registry_factory", "//sdk/src/logs", "//sdk/src/metrics", "//sdk/src/trace", diff --git a/examples/configuration/CMakeLists.txt b/examples/configuration/CMakeLists.txt index a5c31c1b55..571e14b2e5 100644 --- a/examples/configuration/CMakeLists.txt +++ b/examples/configuration/CMakeLists.txt @@ -69,7 +69,8 @@ if(DEFINED OPENTELEMETRY_BUILD_DLL) else() target_link_libraries( example_yaml - PRIVATE opentelemetry-cpp::configuration opentelemetry-cpp::common + PRIVATE opentelemetry-cpp::configuration_registry_factory + opentelemetry-cpp::configuration opentelemetry-cpp::common opentelemetry-cpp::trace opentelemetry-cpp::logs) endif() diff --git a/examples/configuration/main.cc b/examples/configuration/main.cc index c09a39a7b6..428739a67a 100644 --- a/examples/configuration/main.cc +++ b/examples/configuration/main.cc @@ -14,6 +14,7 @@ #include "opentelemetry/sdk/configuration/configuration.h" #include "opentelemetry/sdk/configuration/configured_sdk.h" #include "opentelemetry/sdk/configuration/registry.h" +#include "opentelemetry/sdk/configuration/registry_factory.h" #include "opentelemetry/sdk/configuration/yaml_configuration_parser.h" #include "custom_log_record_exporter_builder.h" @@ -166,7 +167,7 @@ void InitOtel(const std::string &config_file) /* 1 - Create a registry */ std::shared_ptr registry( - new opentelemetry::sdk::configuration::Registry); + opentelemetry::sdk::configuration::RegistryFactory::Create()); /* 2 - Populate the registry with the core components supported */ From 3d02037b8f013aefcf254acac75b2c7b627aba6e Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Fri, 7 Aug 2026 16:38:50 +0000 Subject: [PATCH 16/20] update sdk-default.yaml to highlight the registry methods used to replace the default builders. add the sdk-default.yaml to the example's tests --- examples/configuration/BUILD | 31 ++++ examples/configuration/CMakeLists.txt | 17 +- examples/configuration/sdk-default.yaml | 203 ++++++++---------------- 3 files changed, 114 insertions(+), 137 deletions(-) diff --git a/examples/configuration/BUILD b/examples/configuration/BUILD index 49a672796f..40bc63fe48 100644 --- a/examples/configuration/BUILD +++ b/examples/configuration/BUILD @@ -80,3 +80,34 @@ cc_test( "@com_google_googletest//:gtest_main", ], ) + +cc_test( + name = "example_yaml_sdk_default", + size = "medium", + srcs = glob(["*.cc"]) + glob(["*.h"]), + args = [ + "--test", + "--yaml", + "$(location sdk-default.yaml)", + ], + data = ["sdk-default.yaml"], + tags = [ + "test", + "yaml", + ], + deps = [ + "//api", + "//examples/common/logs_foo_library:common_logs_foo_library", + "//examples/common/metrics_foo_library:common_metrics_foo_library", + "//exporters/ostream:ostream_log_record_exporter_builder", + "//exporters/ostream:ostream_metric_exporter_builder", + "//exporters/ostream:ostream_span_exporter_builder", + "//sdk:headers", + "//sdk/src/configuration", + "//sdk/src/configuration:configuration_registry_factory", + "//sdk/src/logs", + "//sdk/src/metrics", + "//sdk/src/trace", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/examples/configuration/CMakeLists.txt b/examples/configuration/CMakeLists.txt index 571e14b2e5..57e7dcc9e6 100644 --- a/examples/configuration/CMakeLists.txt +++ b/examples/configuration/CMakeLists.txt @@ -75,10 +75,21 @@ else() endif() if(BUILD_TESTING) - add_test(NAME examples.example_yaml_kitchen_sink - COMMAND $ --test --yaml - ${CMAKE_CURRENT_SOURCE_DIR}/kitchen-sink.yaml) + + if(WITH_OTLP_HTTP + AND WITH_OTLP_GRPC + AND WITH_OTLP_FILE + AND WITH_PROMETHEUS) + add_test(NAME examples.example_yaml_kitchen_sink + COMMAND $ --test --yaml + ${CMAKE_CURRENT_SOURCE_DIR}/kitchen-sink.yaml) + endif() + add_test(NAME examples.example_yaml_extensions COMMAND $ --test --yaml ${CMAKE_CURRENT_SOURCE_DIR}/extensions.yaml) + + add_test(NAME examples.example_yaml_sdk_default + COMMAND $ --test --yaml + ${CMAKE_CURRENT_SOURCE_DIR}/sdk-default.yaml) endif() diff --git a/examples/configuration/sdk-default.yaml b/examples/configuration/sdk-default.yaml index c3b455e74d..9757c0eebf 100644 --- a/examples/configuration/sdk-default.yaml +++ b/examples/configuration/sdk-default.yaml @@ -11,175 +11,110 @@ # registry->SetBatchSpanProcessorBuilder(std::make_unique()); # auto sdk = ConfiguredSdk::Create(registry, model); -file_format: "1.0" +file_format: "1.1" disabled: false -log_level: debug - -# Global attribute limits; signal-specific limits below override these. -attribute_limits: - attribute_value_length_limit: 4096 - attribute_count_limit: 128 # --- Logs --- logger_provider: processors: - - batch: # BatchLogRecordProcessorBuilder - schedule_delay: 1000 - export_timeout: 5000 - max_queue_size: 512 - max_export_batch_size: 128 + - batch: # Registry::SetBatchLogRecordProcessorBuilder exporter: - console: # ConsoleLogRecordExporterBuilder - - simple: # SimpleLogRecordProcessorBuilder + console: # Registry::SetConsoleLogRecordBuilder + - simple: # Registry::SetSimpleLogRecordProcessorBuilder exporter: - console: - limits: # overrides attribute_limits for log records - attribute_value_length_limit: 4096 - attribute_count_limit: 128 - logger_configurator/development: # LoggerConfiguratorBuilder + console: # Registry::SetConsoleLogRecordBuilder + logger_configurator/development: # Registry::SetLoggerConfiguratorBuilder default_config: enabled: true - minimum_severity: trace - trace_based: false - loggers: - - name: "io.opentelemetry.*" - config: - enabled: true - minimum_severity: trace - trace_based: false - - name: "noisy.*" - config: - enabled: false # --- Metrics --- meter_provider: readers: - - periodic: # PeriodicMetricReaderBuilder - interval: 10000 - timeout: 5000 + - periodic: # Registry::SetPeriodicMetricReaderBuilder exporter: - console: # ConsolePushMetricExporterBuilder - cardinality_limits: - default: 2000 - counter: 1000 - histogram: 500 - views: - # explicit_bucket_histogram aggregation - - selector: - instrument_name: "my.histogram.*" - instrument_type: histogram - stream: - aggregation: - explicit_bucket_histogram: - boundaries: [0, 5, 10, 25, 50, 100, 250, 500, 1000] - record_min_max: true - aggregation_cardinality_limit: 500 - # base2_exponential_bucket_histogram aggregation - - selector: - instrument_name: "my.exp_histogram.*" - instrument_type: histogram - stream: - aggregation: - base2_exponential_bucket_histogram: - max_size: 160 - max_scale: 20 - record_min_max: true - # drop aggregation - - selector: - instrument_name: "my.dropped.*" - instrument_type: counter - stream: - aggregation: - drop: - # last_value aggregation - - selector: - instrument_name: "my.gauge.*" - instrument_type: observable_gauge - stream: - aggregation: - last_value: - # sum aggregation - - selector: - instrument_name: "my.sum.*" - instrument_type: up_down_counter - stream: - aggregation: - sum: - # default aggregation - - selector: - instrument_name: "my.default.*" - instrument_type: counter - stream: - aggregation: - default: - meter_configurator/development: # MeterConfiguratorBuilder + console: # Registry::SetConsolePushMetricExporterBuilder + meter_configurator/development: # Registry::SetMeterConfiguratorBuilder default_config: enabled: true - meters: - - name: "io.opentelemetry.*" - config: - enabled: true - - name: "noisy.*" - config: - enabled: false # --- Propagators --- propagator: composite: - - tracecontext: - - baggage: - - b3: - - b3multi: - - jaeger: + - tracecontext: # Registry::SetTextMapPropagatorBuilder("tracecontext") + - baggage: # Registry::SetTextMapPropagatorBuilder("baggage") + - b3: # Registry::SetTextMapPropagatorBuilder("b3") + - b3multi: # Registry::SetTextMapPropagatorBuilder("b3multi") + - jaeger: # Registry::SetTextMapPropagatorBuilder("jaeger") # --- Traces --- tracer_provider: processors: - - batch: # BatchSpanProcessorBuilder - schedule_delay: 1000 - export_timeout: 5000 - max_queue_size: 512 - max_export_batch_size: 128 + - batch: # Registry::SetBatchSpanProcessorBuilder exporter: - console: # ConsoleSpanExporterBuilder - - simple: # SimpleSpanProcessorBuilder + console: # Registry::SetConsoleSpanBuilder + - simple: # Registry::SetSimpleSpanProcessorBuilder exporter: - console: # ConsoleSpanExporterBuilder - limits: # overrides attribute_limits for spans - attribute_value_length_limit: 4096 - attribute_count_limit: 128 - event_count_limit: 128 - link_count_limit: 128 - event_attribute_count_limit: 128 - link_attribute_count_limit: 128 - sampler: - parent_based: # ParentBasedSamplerBuilder + console: # Registry::SetConsoleSpanBuilder + sampler: # See kitchen-sink.yaml for sampler field semantics. + parent_based: # Registry::SetParentBasedSamplerBuilder root: - probability/development: # ProbabilitySamplerBuilder - ratio: 0.25 + composite/development: + rule_based: # Registry::SetComposableRuleBasedSamplerBuilder + rules: + - span_kinds: + - internal + sampler: + always_on: # Registry::SetComposableAlwaysOnSamplerBuilder + - attribute_patterns: + key: http.url + included: + - .*/health* + excluded: + - .*/healthz/live + sampler: + always_off: # Registry::SetComposableAlwaysOffSamplerBuilder + - attribute_values: + key: http.response.status_code + values: + - "500" + - "503" + sampler: + always_on: # Registry::SetComposableAlwaysOnSamplerBuilder + - span_kinds: + - server + - consumer + parent: + - none + sampler: + parent_threshold: # Registry::SetComposableParentThresholdSamplerBuilder + root: + probability: # Registry::SetComposableProbabilitySamplerBuilder + ratio: 0.25 + - sampler: + probability: # Registry::SetComposableProbabilitySamplerBuilder + ratio: 0.01 remote_parent_sampled: - always_on: # AlwaysOnSamplerBuilder + always_on: # Registry::SetAlwaysOnSamplerBuilder remote_parent_not_sampled: - always_off: # AlwaysOffSamplerBuilder + trace_id_ratio_based: # Registry::SetTraceIdRatioBasedSamplerBuilder + ratio: 0.001 local_parent_sampled: - always_on: # AlwaysOnSamplerBuilder + always_off: # Registry::SetAlwaysOffSamplerBuilder local_parent_not_sampled: - always_off: # AlwaysOffSamplerBuilder - tracer_configurator/development: # TracerConfiguratorBuilder + probability/development: # Registry::SetProbabilitySamplerBuilder + ratio: 0.001 + + tracer_configurator/development: # Registry::SetTracerConfiguratorBuilder default_config: enabled: false - tracers: - - name: "io.opentelemetry.*" - config: - enabled: true - - name: "noisy.*" - config: - enabled: false -# Resource identifies this service instance. resource: attributes: - name: service.name value: sdk-builtin-test - attributes_list: "service.namespace=my-namespace,service.version=1.0.0" - schema_url: https://opentelemetry.io/schemas/1.43.0 + detection/development: + detectors: + - container: # Registry::SetContainerResourceDetectorBuilder + - host: # Registry::SetHostResourceDetectorBuilder + - process: # Registry::SetProcessResourceDetectorBuilder + - service: # Registry::SetServiceResourceDetectorBuilder From 08d6f1f819d29012bc938fd91870399c099fc21c Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Fri, 7 Aug 2026 14:24:48 -0400 Subject: [PATCH 17/20] fix hidden merge conflict on bazel file. clean up config example cmake file --- examples/configuration/BUILD | 30 --------------------------- examples/configuration/CMakeLists.txt | 16 ++------------ 2 files changed, 2 insertions(+), 44 deletions(-) diff --git a/examples/configuration/BUILD b/examples/configuration/BUILD index 5e82b99090..40bc63fe48 100644 --- a/examples/configuration/BUILD +++ b/examples/configuration/BUILD @@ -111,33 +111,3 @@ cc_test( "@com_google_googletest//:gtest_main", ], ) - -cc_test( - name = "example_yaml_extensions", - size = "medium", - srcs = glob(["*.cc"]) + glob(["*.h"]), - args = [ - "--test", - "--yaml", - "$(location extensions.yaml)", - ], - data = ["extensions.yaml"], - tags = [ - "test", - "yaml", - ], - deps = [ - "//api", - "//examples/common/logs_foo_library:common_logs_foo_library", - "//examples/common/metrics_foo_library:common_metrics_foo_library", - "//exporters/ostream:ostream_log_record_exporter_builder", - "//exporters/ostream:ostream_metric_exporter_builder", - "//exporters/ostream:ostream_span_exporter_builder", - "//sdk:headers", - "//sdk/src/configuration", - "//sdk/src/logs", - "//sdk/src/metrics", - "//sdk/src/trace", - "@com_google_googletest//:gtest_main", - ], -) diff --git a/examples/configuration/CMakeLists.txt b/examples/configuration/CMakeLists.txt index 57e7dcc9e6..2c07516270 100644 --- a/examples/configuration/CMakeLists.txt +++ b/examples/configuration/CMakeLists.txt @@ -22,6 +22,8 @@ add_executable( target_link_libraries( example_yaml PRIVATE ${CMAKE_THREAD_LIBS_INIT} + opentelemetry-cpp::configuration_registry_factory + opentelemetry-cpp::configuration common_metrics_foo_library common_logs_foo_library opentelemetry-cpp::ostream_span_exporter_builder @@ -61,21 +63,7 @@ if(WITH_PROMETHEUS) PRIVATE opentelemetry-cpp::prometheus_exporter_builder) endif() -if(DEFINED OPENTELEMETRY_BUILD_DLL) - target_compile_definitions(example_yaml - PRIVATE OPENTELEMETRY_BUILD_IMPORT_DLL) - target_link_libraries(example_yaml - PRIVATE opentelemetry-cpp::opentelemetry_cpp) -else() - target_link_libraries( - example_yaml - PRIVATE opentelemetry-cpp::configuration_registry_factory - opentelemetry-cpp::configuration opentelemetry-cpp::common - opentelemetry-cpp::trace opentelemetry-cpp::logs) -endif() - if(BUILD_TESTING) - if(WITH_OTLP_HTTP AND WITH_OTLP_GRPC AND WITH_OTLP_FILE From 1ded9c964947e88cdfc4cf55a76bf9b7cad19b18 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Fri, 7 Aug 2026 20:21:48 -0400 Subject: [PATCH 18/20] Create composite sampler builder interface. Create the default composite sampler builder and use it in the sdk builder. Enforce a max sampler depth for composable samplers --- .../composable_rule_based_sampler_builder.h | 2 + .../configuration/composite_sampler_builder.h | 38 +++++++++ .../sdk/configuration/registry.h | 9 +++ .../sdk/configuration/sdk_builder.h | 47 +++++++++++ sdk/src/configuration/logs_builders.cc | 1 + sdk/src/configuration/metrics_builders.cc | 1 + sdk/src/configuration/registry.cc | 6 ++ sdk/src/configuration/sdk_builder.cc | 31 ++++--- sdk/src/configuration/trace_builders.cc | 80 +++++++++++++++++-- sdk/test/configuration/registry_test.cc | 18 +++++ sdk/test/configuration/sdk_builder_test.cc | 74 ++++++++++++++--- sdk/test/configuration/trace_builders_test.cc | 2 + 12 files changed, 282 insertions(+), 27 deletions(-) create mode 100644 sdk/include/opentelemetry/sdk/configuration/composite_sampler_builder.h diff --git a/sdk/include/opentelemetry/sdk/configuration/composable_rule_based_sampler_builder.h b/sdk/include/opentelemetry/sdk/configuration/composable_rule_based_sampler_builder.h index 42736dbc02..de437d8519 100644 --- a/sdk/include/opentelemetry/sdk/configuration/composable_rule_based_sampler_builder.h +++ b/sdk/include/opentelemetry/sdk/configuration/composable_rule_based_sampler_builder.h @@ -31,6 +31,8 @@ class ComposableRuleBasedSamplerBuilder default; virtual ~ComposableRuleBasedSamplerBuilder() = default; + /// rule_samplers is index-aligned with model->rules. Entries are null for + /// rules with no sampler, which implementations must skip. virtual std::unique_ptr Build( const opentelemetry::sdk::configuration::ComposableRuleBasedSamplerConfiguration *model, std::vector> &&rule_samplers) diff --git a/sdk/include/opentelemetry/sdk/configuration/composite_sampler_builder.h b/sdk/include/opentelemetry/sdk/configuration/composite_sampler_builder.h new file mode 100644 index 0000000000..5dde7ec417 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/composite_sampler_builder.h @@ -0,0 +1,38 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace trace +{ +class ComposableSampler; +class Sampler; +} // namespace trace + +namespace configuration +{ + +class CompositeSamplerBuilder +{ +public: + CompositeSamplerBuilder() = default; + CompositeSamplerBuilder(CompositeSamplerBuilder &&) = default; + CompositeSamplerBuilder(const CompositeSamplerBuilder &) = default; + CompositeSamplerBuilder &operator=(CompositeSamplerBuilder &&) = default; + CompositeSamplerBuilder &operator=(const CompositeSamplerBuilder &other) = default; + virtual ~CompositeSamplerBuilder() = default; + + virtual std::unique_ptr Build( + std::unique_ptr &&sampler) const = 0; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/registry.h b/sdk/include/opentelemetry/sdk/configuration/registry.h index 3df10b92be..7e5dce3d24 100644 --- a/sdk/include/opentelemetry/sdk/configuration/registry.h +++ b/sdk/include/opentelemetry/sdk/configuration/registry.h @@ -25,6 +25,7 @@ class ComposableAlwaysOnSamplerBuilder; class ComposableParentThresholdSamplerBuilder; class ComposableProbabilitySamplerBuilder; class ComposableRuleBasedSamplerBuilder; +class CompositeSamplerBuilder; class ConsoleLogRecordExporterBuilder; class ConsolePushMetricExporterBuilder; class ConsoleSpanExporterBuilder; @@ -283,6 +284,13 @@ class OPENTELEMETRY_EXPORT Registry void SetComposableRuleBasedSamplerBuilder( std::unique_ptr &&builder); + const CompositeSamplerBuilder *GetCompositeSamplerBuilder() const + { + return composite_sampler_builder_.get(); + } + + void SetCompositeSamplerBuilder(std::unique_ptr &&builder); + /* Processors. */ const BatchSpanProcessorBuilder *GetBatchSpanProcessorBuilder() const @@ -465,6 +473,7 @@ class OPENTELEMETRY_EXPORT Registry std::unique_ptr composable_parent_threshold_sampler_builder_; std::unique_ptr composable_rule_based_sampler_builder_; + std::unique_ptr composite_sampler_builder_; std::unique_ptr batch_span_processor_builder_; std::unique_ptr simple_span_processor_builder_; diff --git a/sdk/include/opentelemetry/sdk/configuration/sdk_builder.h b/sdk/include/opentelemetry/sdk/configuration/sdk_builder.h index c1c17edb99..7dae1952b8 100644 --- a/sdk/include/opentelemetry/sdk/configuration/sdk_builder.h +++ b/sdk/include/opentelemetry/sdk/configuration/sdk_builder.h @@ -3,6 +3,7 @@ #pragma once +#include #include #include "opentelemetry/sdk/configuration/always_off_sampler_configuration.h" @@ -67,12 +68,27 @@ OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { +namespace trace +{ +class ComposableSampler; +} // namespace trace + namespace configuration { +class ComposableAlwaysOffSamplerConfiguration; +class ComposableAlwaysOnSamplerConfiguration; +class ComposableParentThresholdSamplerConfiguration; +class ComposableProbabilitySamplerConfiguration; +class ComposableRuleBasedSamplerConfiguration; +class ComposableSamplerConfiguration; + class SdkBuilder { public: + /// Maximum nesting depth of composable samplers, root included. + static constexpr std::size_t kDefaultMaxComposableSamplerDepth = 10; + SdkBuilder(std::shared_ptr registry) : registry_(std::move(registry)) {} SdkBuilder(SdkBuilder &&) = default; SdkBuilder(const SdkBuilder &) = default; @@ -104,6 +120,36 @@ class SdkBuilder std::unique_ptr CreateSampler( const std::unique_ptr &model) const; + std::unique_ptr CreateComposableAlwaysOffSampler( + const opentelemetry::sdk::configuration::ComposableAlwaysOffSamplerConfiguration *model) + const; + + std::unique_ptr CreateComposableAlwaysOnSampler( + const opentelemetry::sdk::configuration::ComposableAlwaysOnSamplerConfiguration *model) const; + + std::unique_ptr CreateComposableProbabilitySampler( + const opentelemetry::sdk::configuration::ComposableProbabilitySamplerConfiguration *model) + const; + + std::unique_ptr + CreateComposableParentThresholdSampler( + const opentelemetry::sdk::configuration::ComposableParentThresholdSamplerConfiguration *model, + std::size_t depth = 1) const; + + std::unique_ptr CreateComposableRuleBasedSampler( + const opentelemetry::sdk::configuration::ComposableRuleBasedSamplerConfiguration *model, + std::size_t depth = 1) const; + + /// Throws UnsupportedException when depth exceeds the maximum. + std::unique_ptr CreateComposableSampler( + const opentelemetry::sdk::configuration::ComposableSamplerConfiguration *model, + std::size_t depth = 1) const; + + void SetMaxComposableSamplerDepth(std::size_t depth) { max_composable_sampler_depth_ = depth; } + + std::unique_ptr CreateCompositeSampler( + const opentelemetry::sdk::configuration::ComposableSamplerConfiguration *model) const; + std::unique_ptr CreateOtlpHttpSpanExporter( const opentelemetry::sdk::configuration::OtlpHttpSpanExporterConfiguration *model) const; @@ -286,6 +332,7 @@ class SdkBuilder private: std::shared_ptr registry_; + std::size_t max_composable_sampler_depth_{kDefaultMaxComposableSamplerDepth}; }; } // namespace configuration diff --git a/sdk/src/configuration/logs_builders.cc b/sdk/src/configuration/logs_builders.cc index e29f8e4803..b08a90efc2 100644 --- a/sdk/src/configuration/logs_builders.cc +++ b/sdk/src/configuration/logs_builders.cc @@ -11,6 +11,7 @@ #include #include "opentelemetry/logs/severity.h" +#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/configuration/batch_log_record_processor_builder.h" #include "opentelemetry/sdk/configuration/batch_log_record_processor_configuration.h" #include "opentelemetry/sdk/configuration/logger_config_configuration.h" diff --git a/sdk/src/configuration/metrics_builders.cc b/sdk/src/configuration/metrics_builders.cc index 00b4493628..0c113fb1a4 100644 --- a/sdk/src/configuration/metrics_builders.cc +++ b/sdk/src/configuration/metrics_builders.cc @@ -10,6 +10,7 @@ #include #include +#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/configuration/meter_config_configuration.h" #include "opentelemetry/sdk/configuration/meter_configurator_builder.h" #include "opentelemetry/sdk/configuration/meter_configurator_configuration.h" diff --git a/sdk/src/configuration/registry.cc b/sdk/src/configuration/registry.cc index 53b37951cd..18d5ee3df8 100644 --- a/sdk/src/configuration/registry.cc +++ b/sdk/src/configuration/registry.cc @@ -17,6 +17,7 @@ #include "opentelemetry/sdk/configuration/composable_parent_threshold_sampler_builder.h" #include "opentelemetry/sdk/configuration/composable_probability_sampler_builder.h" #include "opentelemetry/sdk/configuration/composable_rule_based_sampler_builder.h" +#include "opentelemetry/sdk/configuration/composite_sampler_builder.h" #include "opentelemetry/sdk/configuration/console_log_record_exporter_builder.h" #include "opentelemetry/sdk/configuration/console_push_metric_exporter_builder.h" #include "opentelemetry/sdk/configuration/console_span_exporter_builder.h" @@ -286,6 +287,11 @@ void Registry::SetComposableRuleBasedSamplerBuilder( composable_rule_based_sampler_builder_ = std::move(builder); } +void Registry::SetCompositeSamplerBuilder(std::unique_ptr &&builder) +{ + composite_sampler_builder_ = std::move(builder); +} + void Registry::SetBatchSpanProcessorBuilder(std::unique_ptr &&builder) { batch_span_processor_builder_ = std::move(builder); diff --git a/sdk/src/configuration/sdk_builder.cc b/sdk/src/configuration/sdk_builder.cc index d26ce5032c..aca1a016cf 100644 --- a/sdk/src/configuration/sdk_builder.cc +++ b/sdk/src/configuration/sdk_builder.cc @@ -44,8 +44,6 @@ #include "opentelemetry/sdk/configuration/composable_probability_sampler_configuration.h" #include "opentelemetry/sdk/configuration/composable_rule_based_sampler_builder.h" #include "opentelemetry/sdk/configuration/composable_rule_based_sampler_configuration.h" -#include "opentelemetry/sdk/configuration/composable_rule_based_sampler_rule_attribute_patterns_configuration.h" -#include "opentelemetry/sdk/configuration/composable_rule_based_sampler_rule_attribute_values_configuration.h" #include "opentelemetry/sdk/configuration/composable_rule_based_sampler_rule_configuration.h" #include "opentelemetry/sdk/configuration/composable_sampler_configuration.h" #include "opentelemetry/sdk/configuration/composite_sampler_builder.h" @@ -79,7 +77,6 @@ #include "opentelemetry/sdk/configuration/instrument_type.h" #include "opentelemetry/sdk/configuration/integer_array_attribute_value_configuration.h" #include "opentelemetry/sdk/configuration/integer_attribute_value_configuration.h" -#include "opentelemetry/sdk/configuration/invalid_configuration_exception.h" #include "opentelemetry/sdk/configuration/jaeger_remote_sampler_builder.h" #include "opentelemetry/sdk/configuration/jaeger_remote_sampler_configuration.h" #include "opentelemetry/sdk/configuration/log_record_exporter_configuration.h" @@ -382,6 +379,13 @@ class ComposableSamplerBuilder ComposableSamplerBuilder &operator=(const ComposableSamplerBuilder &other) = delete; ~ComposableSamplerBuilder() override = default; + // The yaml schema supports infinite sampler nesting due to the + // ExperimentalComposableRuleBasedSampler containing an array of + // ExperimentalComposableRuleBasedSamplerRule which each may contain a + // ExperimentalComposableRuleBasedSampler (See: schema/tracer_provider.yaml#L340). + // Recursion is used to build the nested samplers, but the depth of recursion is limited to + // (max_composable_sampler_depth_). + // // NOLINTBEGIN(misc-no-recursion) void VisitComposableAlwaysOff( const opentelemetry::sdk::configuration::ComposableAlwaysOffSamplerConfiguration *model) @@ -420,53 +424,56 @@ class ComposableSamplerBuilder // NOLINTEND(misc-no-recursion) // The model only ever nests ComposableSamplerConfiguration here, so the - // plain sampler visits are unreachable. + // plain sampler visits are unreachable. Throw to preserve the invariant + // that a null sampler is never returned. void VisitAlwaysOff( const opentelemetry::sdk::configuration::AlwaysOffSamplerConfiguration * /* model */) override { - OTEL_INTERNAL_LOG_ERROR("Expecting a composable sampler"); + throw UnsupportedException(kNotComposable); } void VisitAlwaysOn( const opentelemetry::sdk::configuration::AlwaysOnSamplerConfiguration * /* model */) override { - OTEL_INTERNAL_LOG_ERROR("Expecting a composable sampler"); + throw UnsupportedException(kNotComposable); } void VisitJaegerRemote(const opentelemetry::sdk::configuration::JaegerRemoteSamplerConfiguration * /* model */) override { - OTEL_INTERNAL_LOG_ERROR("Expecting a composable sampler"); + throw UnsupportedException(kNotComposable); } void VisitParentBased(const opentelemetry::sdk::configuration::ParentBasedSamplerConfiguration * /* model */) override { - OTEL_INTERNAL_LOG_ERROR("Expecting a composable sampler"); + throw UnsupportedException(kNotComposable); } void VisitProbability(const opentelemetry::sdk::configuration::ProbabilitySamplerConfiguration * /* model */) override { - OTEL_INTERNAL_LOG_ERROR("Expecting a composable sampler"); + throw UnsupportedException(kNotComposable); } void VisitTraceIdRatioBased( const opentelemetry::sdk::configuration::TraceIdRatioBasedSamplerConfiguration * /* model */) override { - OTEL_INTERNAL_LOG_ERROR("Expecting a composable sampler"); + throw UnsupportedException(kNotComposable); } void VisitExtension( const opentelemetry::sdk::configuration::ExtensionSamplerConfiguration * /* model */) override { - OTEL_INTERNAL_LOG_ERROR("Expecting a composable sampler"); + throw UnsupportedException(kNotComposable); } std::unique_ptr sampler; private: + static constexpr const char *kNotComposable = "Expecting a composable sampler"; + const SdkBuilder *sdk_builder_; std::size_t depth_; }; @@ -1129,7 +1136,7 @@ std::unique_ptr SdkBuilder::Create { std::string die("Composable sampler nesting depth exceeds "); die.append(std::to_string(max_composable_sampler_depth_)); - throw InvalidConfigurationException(die); + throw UnsupportedException(die); } ComposableSamplerBuilder builder(this, depth); model->Accept(&builder); diff --git a/sdk/src/configuration/trace_builders.cc b/sdk/src/configuration/trace_builders.cc index 980e883ba9..940d1346b6 100644 --- a/sdk/src/configuration/trace_builders.cc +++ b/sdk/src/configuration/trace_builders.cc @@ -4,12 +4,14 @@ #include "opentelemetry/sdk/configuration/trace_builders.h" #include +#include #include #include #include #include #include +#include "opentelemetry/nostd/string_view.h" #include "opentelemetry/sdk/configuration/always_off_sampler_builder.h" #include "opentelemetry/sdk/configuration/always_on_sampler_builder.h" #include "opentelemetry/sdk/configuration/batch_span_processor_builder.h" @@ -20,6 +22,11 @@ #include "opentelemetry/sdk/configuration/composable_probability_sampler_builder.h" #include "opentelemetry/sdk/configuration/composable_probability_sampler_configuration.h" #include "opentelemetry/sdk/configuration/composable_rule_based_sampler_builder.h" +#include "opentelemetry/sdk/configuration/composable_rule_based_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/composable_rule_based_sampler_rule_attribute_patterns_configuration.h" +#include "opentelemetry/sdk/configuration/composable_rule_based_sampler_rule_attribute_values_configuration.h" +#include "opentelemetry/sdk/configuration/composable_rule_based_sampler_rule_configuration.h" +#include "opentelemetry/sdk/configuration/composite_sampler_builder.h" #include "opentelemetry/sdk/configuration/jaeger_remote_sampler_builder.h" #include "opentelemetry/sdk/configuration/parent_based_sampler_builder.h" #include "opentelemetry/sdk/configuration/probability_sampler_builder.h" @@ -45,9 +52,12 @@ #include "opentelemetry/sdk/trace/samplers/composable_always_on.h" #include "opentelemetry/sdk/trace/samplers/composable_parent_threshold.h" #include "opentelemetry/sdk/trace/samplers/composable_probability.h" +#include "opentelemetry/sdk/trace/samplers/composable_rule_based.h" #include "opentelemetry/sdk/trace/samplers/composable_sampler.h" +#include "opentelemetry/sdk/trace/samplers/composite_sampler_factory.h" #include "opentelemetry/sdk/trace/samplers/parent_factory.h" #include "opentelemetry/sdk/trace/samplers/probability_factory.h" +#include "opentelemetry/sdk/trace/samplers/rule_based_predicate.h" #include "opentelemetry/sdk/trace/samplers/trace_id_ratio_factory.h" #include "opentelemetry/sdk/trace/simple_processor_factory.h" #include "opentelemetry/sdk/trace/tracer_config.h" @@ -212,14 +222,73 @@ class DefaultComposableRuleBasedSamplerBuilder : public ComposableRuleBasedSampl { public: std::unique_ptr Build( - const ComposableRuleBasedSamplerConfiguration * /* model */, + const ComposableRuleBasedSamplerConfiguration *model, std::vector> &&rule_samplers) const override { - auto unused = std::move(rule_samplers); - // TODO: implement once a concrete Predicate can be built from rule config - static const std::string die("ComposableRuleBasedSampler not supported"); - throw UnsupportedException(die); + auto owned_samplers = std::move(rule_samplers); + if (owned_samplers.size() != model->rules.size()) + { + throw UnsupportedException("rule_samplers size does not match rules size"); + } + std::vector rules; + rules.reserve(model->rules.size()); + for (std::size_t i = 0; i < owned_samplers.size(); ++i) + { + // rule_samplers is index-aligned with model->rules; null means no sampler. + if (owned_samplers[i] == nullptr) + { + continue; + } + opentelemetry::sdk::trace::PredicatedSampler predicated; + predicated.predicate = std::make_shared( + MakePredicateOptions(model->rules[i].get())); + predicated.sampler = std::move(owned_samplers[i]); + rules.push_back(std::move(predicated)); + } + return std::make_unique( + std::move(rules)); + } + +private: + static opentelemetry::sdk::trace::RuleBasedPredicateOptions MakePredicateOptions( + const opentelemetry::sdk::configuration::ComposableRuleBasedSamplerRuleConfiguration *rule) + { + opentelemetry::sdk::trace::RuleBasedPredicateOptions options; + if (rule->attribute_values != nullptr) + { + options.match_values = true; + options.values_key = rule->attribute_values->key; + options.values = rule->attribute_values->values; + } + if (rule->attribute_patterns != nullptr) + { + options.match_patterns = true; + options.patterns_key = rule->attribute_patterns->key; + options.included = rule->attribute_patterns->included; + options.excluded = rule->attribute_patterns->excluded; + } + options.match_parent_none = rule->match_parent_none; + options.match_parent_remote = rule->match_parent_remote; + options.match_parent_local = rule->match_parent_local; + + options.match_span_kind_internal = rule->match_span_kind_internal; + options.match_span_kind_server = rule->match_span_kind_server; + options.match_span_kind_client = rule->match_span_kind_client; + options.match_span_kind_producer = rule->match_span_kind_producer; + options.match_span_kind_consumer = rule->match_span_kind_consumer; + return options; + } +}; + +class DefaultCompositeSamplerBuilder : public CompositeSamplerBuilder +{ +public: + std::unique_ptr Build( + std::unique_ptr &&sampler) const override + { + return opentelemetry::sdk::trace::CompositeSamplerFactory::Create( + std::shared_ptr(std::move(sampler))); } }; @@ -279,6 +348,7 @@ void RegisterDefaultTraceBuilders(Registry *registry) std::make_unique()); registry->SetComposableRuleBasedSamplerBuilder( std::make_unique()); + registry->SetCompositeSamplerBuilder(std::make_unique()); } } // namespace configuration diff --git a/sdk/test/configuration/registry_test.cc b/sdk/test/configuration/registry_test.cc index d44b4d7eb7..a498156b58 100644 --- a/sdk/test/configuration/registry_test.cc +++ b/sdk/test/configuration/registry_test.cc @@ -16,6 +16,7 @@ #include "opentelemetry/sdk/configuration/composable_parent_threshold_sampler_builder.h" #include "opentelemetry/sdk/configuration/composable_probability_sampler_builder.h" #include "opentelemetry/sdk/configuration/composable_rule_based_sampler_builder.h" +#include "opentelemetry/sdk/configuration/composite_sampler_builder.h" #include "opentelemetry/sdk/configuration/console_log_record_exporter_builder.h" #include "opentelemetry/sdk/configuration/console_push_metric_exporter_builder.h" #include "opentelemetry/sdk/configuration/console_span_exporter_builder.h" @@ -212,6 +213,17 @@ class TestComposableRuleBasedSamplerBuilder } }; +class TestCompositeSamplerBuilder : public configuration::CompositeSamplerBuilder +{ +public: + std::unique_ptr Build( + std::unique_ptr &&sampler) const override + { + auto unused = std::move(sampler); + return nullptr; + } +}; + class TestBatchSpanProcessorBuilder : public configuration::BatchSpanProcessorBuilder { public: @@ -727,6 +739,12 @@ TEST(Registry, ComposableRuleBasedSamplerBuilder) &configuration::Registry::SetComposableRuleBasedSamplerBuilder); } +TEST(Registry, CompositeSamplerBuilder) +{ + TestTypedSlot(&configuration::Registry::GetCompositeSamplerBuilder, + &configuration::Registry::SetCompositeSamplerBuilder); +} + TEST(Registry, BatchSpanProcessorBuilder) { TestTypedSlot( diff --git a/sdk/test/configuration/sdk_builder_test.cc b/sdk/test/configuration/sdk_builder_test.cc index f737e4f412..735bb36a4a 100644 --- a/sdk/test/configuration/sdk_builder_test.cc +++ b/sdk/test/configuration/sdk_builder_test.cc @@ -49,6 +49,7 @@ #include "opentelemetry/sdk/configuration/span_limits_configuration.h" #include "opentelemetry/sdk/configuration/trace_id_ratio_based_sampler_configuration.h" #include "opentelemetry/sdk/configuration/tracer_provider_configuration.h" +#include "opentelemetry/sdk/configuration/unsupported_exception.h" #include "opentelemetry/sdk/configuration/view_configuration.h" #include "opentelemetry/sdk/configuration/view_selector_configuration.h" #include "opentelemetry/sdk/configuration/view_stream_configuration.h" @@ -123,7 +124,7 @@ std::unique_ptr BuildRuleSampler( auto rule_based_config = std::make_unique(); rule_based_config->rules.push_back(std::move(rule)); std::unique_ptr sampler_config = std::move(rule_based_config); - config_sdk::SdkBuilder builder(std::make_shared()); + config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); return builder.CreateSampler(sampler_config); } @@ -341,7 +342,7 @@ TEST(SdkBuilder, CreateComposableAlwaysOnSampler) { auto composable_config = std::make_unique(); std::unique_ptr sampler_config = std::move(composable_config); - config_sdk::SdkBuilder builder(std::make_shared()); + config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateSampler(sampler_config); ASSERT_NE(sampler, nullptr); EXPECT_EQ(std::string{sampler->GetDescription()}, @@ -352,7 +353,7 @@ TEST(SdkBuilder, CreateComposableAlwaysOffSampler) { auto composable_config = std::make_unique(); std::unique_ptr sampler_config = std::move(composable_config); - config_sdk::SdkBuilder builder(std::make_shared()); + config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateSampler(sampler_config); ASSERT_NE(sampler, nullptr); EXPECT_EQ(std::string{sampler->GetDescription()}, @@ -366,7 +367,7 @@ TEST(SdkBuilder, CreateComposableProbabilitySampler) composable_probability_sampler_config->ratio = 0.25; std::unique_ptr sampler_config = std::move(composable_probability_sampler_config); - config_sdk::SdkBuilder builder(std::make_shared()); + config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateSampler(sampler_config); ASSERT_NE(sampler, nullptr); EXPECT_EQ(std::string{sampler->GetDescription()}, @@ -381,7 +382,7 @@ TEST(SdkBuilder, CreateComposableParentThresholdSampler) std::make_unique(); parent_config->root = std::move(root_config); std::unique_ptr sampler_config = std::move(parent_config); - config_sdk::SdkBuilder builder(std::make_shared()); + config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateSampler(sampler_config); ASSERT_NE(sampler, nullptr); EXPECT_EQ( @@ -395,7 +396,7 @@ TEST(SdkBuilder, CreateComposableParentThresholdSamplerNullRoot) std::make_unique(); parent_config->root = nullptr; std::unique_ptr sampler_config = std::move(parent_config); - config_sdk::SdkBuilder builder(std::make_shared()); + config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateSampler(sampler_config); ASSERT_NE(sampler, nullptr); EXPECT_EQ(std::string{sampler->GetDescription()}, @@ -415,7 +416,7 @@ TEST(SdkBuilder, CreateComposableParentThresholdSamplerNestedDepth3) outer_config->root = std::move(middle_config); std::unique_ptr sampler_config = std::move(outer_config); - config_sdk::SdkBuilder builder(std::make_shared()); + config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateSampler(sampler_config); ASSERT_NE(sampler, nullptr); EXPECT_EQ(std::string{sampler->GetDescription()}, @@ -423,6 +424,59 @@ TEST(SdkBuilder, CreateComposableParentThresholdSamplerNestedDepth3) R"(ComposableProbabilitySampler{0.250000}}}})"); } +namespace +{ + +// Builds a chain of parent_threshold nodes ending in an always_on leaf. +// Total nesting depth, root included, is num_parent_nodes + 1. +std::unique_ptr MakeNestedComposableConfig( + std::size_t num_parent_nodes) +{ + std::unique_ptr node = + std::make_unique(); + for (std::size_t i = 0; i < num_parent_nodes; ++i) + { + auto parent = std::make_unique(); + parent->root = std::move(node); + node = std::move(parent); + } + return node; +} + +} // namespace + +TEST(SdkBuilder, CreateComposableSamplerAtMaxDepth) +{ + // 9 parent nodes + leaf = depth 10, the default maximum. + auto sampler_config = + MakeNestedComposableConfig(config_sdk::SdkBuilder::kDefaultMaxComposableSamplerDepth - 1); + config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); + auto sampler = builder.CreateSampler(sampler_config); + ASSERT_NE(sampler, nullptr); +} + +TEST(SdkBuilder, CreateComposableSamplerBeyondMaxDepth) +{ + // 10 parent nodes + leaf = depth 11, exceeding the default maximum. + auto sampler_config = + MakeNestedComposableConfig(config_sdk::SdkBuilder::kDefaultMaxComposableSamplerDepth); + config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); + EXPECT_THROW(builder.CreateSampler(sampler_config), config_sdk::UnsupportedException); +} + +TEST(SdkBuilder, SetMaxComposableSamplerDepth) +{ + // 2 parent nodes + leaf = depth 3. + auto sampler_config = MakeNestedComposableConfig(2); + config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); + builder.SetMaxComposableSamplerDepth(2); + EXPECT_THROW(builder.CreateSampler(sampler_config), config_sdk::UnsupportedException); + + auto sampler_config_ok = MakeNestedComposableConfig(1); + auto sampler = builder.CreateSampler(sampler_config_ok); + ASSERT_NE(sampler, nullptr); +} + TEST(SdkBuilder, CreateComposableRuleBasedSampler) { auto rule_based_config = std::make_unique(); @@ -441,7 +495,7 @@ TEST(SdkBuilder, CreateComposableRuleBasedSampler) rule_based_config->rules.push_back(std::move(fallback)); std::unique_ptr sampler_config = std::move(rule_based_config); - config_sdk::SdkBuilder builder(std::make_shared()); + config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateSampler(sampler_config); ASSERT_NE(sampler, nullptr); EXPECT_EQ( @@ -676,7 +730,7 @@ TEST(SdkBuilder, RuleBasedFirstMatchAndDefaults) second->sampler = std::make_unique(); rule_based_config->rules.push_back(std::move(second)); std::unique_ptr sampler_config = std::move(rule_based_config); - config_sdk::SdkBuilder builder(std::make_shared()); + config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateSampler(sampler_config); ASSERT_NE(sampler, nullptr); @@ -688,7 +742,7 @@ TEST(SdkBuilder, RuleBasedFirstMatchAndDefaults) auto rule_based_config = std::make_unique(); std::unique_ptr sampler_config = std::move(rule_based_config); - config_sdk::SdkBuilder builder(std::make_shared()); + config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateSampler(sampler_config); ASSERT_NE(sampler, nullptr); diff --git a/sdk/test/configuration/trace_builders_test.cc b/sdk/test/configuration/trace_builders_test.cc index 1a137c38e6..3a86060878 100644 --- a/sdk/test/configuration/trace_builders_test.cc +++ b/sdk/test/configuration/trace_builders_test.cc @@ -28,6 +28,7 @@ TEST(TraceBuilders, EmptyRegistryHasNoTraceBuilders) EXPECT_EQ(registry->GetComposableProbabilitySamplerBuilder(), nullptr); EXPECT_EQ(registry->GetComposableParentThresholdSamplerBuilder(), nullptr); EXPECT_EQ(registry->GetComposableRuleBasedSamplerBuilder(), nullptr); + EXPECT_EQ(registry->GetCompositeSamplerBuilder(), nullptr); } TEST(TraceBuilders, RegisterDefaultTraceBuildersFillsAllTraceSlots) @@ -50,4 +51,5 @@ TEST(TraceBuilders, RegisterDefaultTraceBuildersFillsAllTraceSlots) EXPECT_NE(registry->GetComposableProbabilitySamplerBuilder(), nullptr); EXPECT_NE(registry->GetComposableParentThresholdSamplerBuilder(), nullptr); EXPECT_NE(registry->GetComposableRuleBasedSamplerBuilder(), nullptr); + EXPECT_NE(registry->GetCompositeSamplerBuilder(), nullptr); } From 3b05f9d2572f29fa5a335da6534dd77c91ce05d6 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Sun, 9 Aug 2026 10:58:01 -0400 Subject: [PATCH 19/20] cleanup the composite/composable sampler model by creating a composite sampler config class and separating the composable config vistor from the top level sampler config visitor. cleanup the sdk builder to use the new composable config visitor. --- install/test/src/test_sdk.cc | 1 + ...posable_always_off_sampler_configuration.h | 2 +- ...mposable_always_on_sampler_configuration.h | 2 +- ...e_parent_threshold_sampler_configuration.h | 2 +- ...osable_probability_sampler_configuration.h | 2 +- ...posable_rule_based_sampler_configuration.h | 2 +- .../composable_sampler_configuration.h | 9 +- ...composable_sampler_configuration_visitor.h | 43 +++ .../composite_sampler_configuration.h | 34 ++ .../sampler_configuration_visitor.h | 29 +- .../sdk/configuration/sdk_builder.h | 36 -- ...osable_always_off_sampler_configuration.cc | 5 +- ...posable_always_on_sampler_configuration.cc | 5 +- ..._parent_threshold_sampler_configuration.cc | 4 +- ...sable_probability_sampler_configuration.cc | 5 +- ...osable_rule_based_sampler_configuration.cc | 5 +- sdk/src/configuration/configuration_parser.cc | 5 +- sdk/src/configuration/sdk_builder.cc | 323 ++++++------------ sdk/test/configuration/sdk_builder_test.cc | 73 ++-- sdk/test/configuration/yaml_trace_test.cc | 77 +++-- 20 files changed, 316 insertions(+), 348 deletions(-) create mode 100644 sdk/include/opentelemetry/sdk/configuration/composable_sampler_configuration_visitor.h create mode 100644 sdk/include/opentelemetry/sdk/configuration/composite_sampler_configuration.h diff --git a/install/test/src/test_sdk.cc b/install/test/src/test_sdk.cc index 9e666f1115..9140366025 100644 --- a/install/test/src/test_sdk.cc +++ b/install/test/src/test_sdk.cc @@ -234,6 +234,7 @@ #include #include #include +#include "opentelemetry/sdk/configuration/composite_sampler_builder.h" // SDK configuration builder headers #include diff --git a/sdk/include/opentelemetry/sdk/configuration/composable_always_off_sampler_configuration.h b/sdk/include/opentelemetry/sdk/configuration/composable_always_off_sampler_configuration.h index dee01a2a0d..9945261c55 100644 --- a/sdk/include/opentelemetry/sdk/configuration/composable_always_off_sampler_configuration.h +++ b/sdk/include/opentelemetry/sdk/configuration/composable_always_off_sampler_configuration.h @@ -16,7 +16,7 @@ class ComposableAlwaysOffSamplerConfiguration : public ComposableSamplerConfigur { public: ComposableAlwaysOffSamplerConfiguration() = default; - void Accept(SamplerConfigurationVisitor *visitor) const override; + void Accept(ComposableSamplerConfigurationVisitor *visitor) const override; }; } // namespace configuration diff --git a/sdk/include/opentelemetry/sdk/configuration/composable_always_on_sampler_configuration.h b/sdk/include/opentelemetry/sdk/configuration/composable_always_on_sampler_configuration.h index 8f414bc249..5bf30b6318 100644 --- a/sdk/include/opentelemetry/sdk/configuration/composable_always_on_sampler_configuration.h +++ b/sdk/include/opentelemetry/sdk/configuration/composable_always_on_sampler_configuration.h @@ -16,7 +16,7 @@ class ComposableAlwaysOnSamplerConfiguration : public ComposableSamplerConfigura { public: ComposableAlwaysOnSamplerConfiguration() = default; - void Accept(SamplerConfigurationVisitor *visitor) const override; + void Accept(ComposableSamplerConfigurationVisitor *visitor) const override; }; } // namespace configuration diff --git a/sdk/include/opentelemetry/sdk/configuration/composable_parent_threshold_sampler_configuration.h b/sdk/include/opentelemetry/sdk/configuration/composable_parent_threshold_sampler_configuration.h index 5ab341746c..8363ad4bb8 100644 --- a/sdk/include/opentelemetry/sdk/configuration/composable_parent_threshold_sampler_configuration.h +++ b/sdk/include/opentelemetry/sdk/configuration/composable_parent_threshold_sampler_configuration.h @@ -22,7 +22,7 @@ class ComposableParentThresholdSamplerConfiguration : public ComposableSamplerCo // Enforce strong typing for the root pointer std::unique_ptr root; - void Accept(SamplerConfigurationVisitor *visitor) const override; + void Accept(ComposableSamplerConfigurationVisitor *visitor) const override; }; } // namespace configuration diff --git a/sdk/include/opentelemetry/sdk/configuration/composable_probability_sampler_configuration.h b/sdk/include/opentelemetry/sdk/configuration/composable_probability_sampler_configuration.h index 64045b5176..44e93e40e8 100644 --- a/sdk/include/opentelemetry/sdk/configuration/composable_probability_sampler_configuration.h +++ b/sdk/include/opentelemetry/sdk/configuration/composable_probability_sampler_configuration.h @@ -21,7 +21,7 @@ class ComposableProbabilitySamplerConfiguration : public ComposableSamplerConfig ComposableProbabilitySamplerConfiguration() = default; double ratio{kDefaultRatio}; - void Accept(SamplerConfigurationVisitor *visitor) const override; + void Accept(ComposableSamplerConfigurationVisitor *visitor) const override; }; } // namespace configuration diff --git a/sdk/include/opentelemetry/sdk/configuration/composable_rule_based_sampler_configuration.h b/sdk/include/opentelemetry/sdk/configuration/composable_rule_based_sampler_configuration.h index cf3e3e4942..5cfff0890f 100644 --- a/sdk/include/opentelemetry/sdk/configuration/composable_rule_based_sampler_configuration.h +++ b/sdk/include/opentelemetry/sdk/configuration/composable_rule_based_sampler_configuration.h @@ -21,7 +21,7 @@ class ComposableRuleBasedSamplerConfiguration : public ComposableSamplerConfigur public: ComposableRuleBasedSamplerConfiguration() = default; std::vector> rules; - void Accept(SamplerConfigurationVisitor *visitor) const override; + void Accept(ComposableSamplerConfigurationVisitor *visitor) const override; }; } // namespace configuration diff --git a/sdk/include/opentelemetry/sdk/configuration/composable_sampler_configuration.h b/sdk/include/opentelemetry/sdk/configuration/composable_sampler_configuration.h index 7d1bf96fd1..49dde6207b 100644 --- a/sdk/include/opentelemetry/sdk/configuration/composable_sampler_configuration.h +++ b/sdk/include/opentelemetry/sdk/configuration/composable_sampler_configuration.h @@ -3,8 +3,7 @@ #pragma once -#include "opentelemetry/sdk/configuration/sampler_configuration.h" -#include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" +#include "opentelemetry/sdk/configuration/composable_sampler_configuration_visitor.h" #include "opentelemetry/version.h" OPENTELEMETRY_BEGIN_NAMESPACE @@ -12,15 +11,17 @@ namespace sdk { namespace configuration { -class ComposableSamplerConfiguration : public SamplerConfiguration +class ComposableSamplerConfiguration { public: ComposableSamplerConfiguration() = default; - ~ComposableSamplerConfiguration() override = default; + virtual ~ComposableSamplerConfiguration() = default; ComposableSamplerConfiguration(const ComposableSamplerConfiguration &) = default; ComposableSamplerConfiguration(ComposableSamplerConfiguration &&) = default; ComposableSamplerConfiguration &operator=(const ComposableSamplerConfiguration &) = default; ComposableSamplerConfiguration &operator=(ComposableSamplerConfiguration &&) = default; + + virtual void Accept(ComposableSamplerConfigurationVisitor *visitor) const = 0; }; } // namespace configuration } // namespace sdk diff --git a/sdk/include/opentelemetry/sdk/configuration/composable_sampler_configuration_visitor.h b/sdk/include/opentelemetry/sdk/configuration/composable_sampler_configuration_visitor.h new file mode 100644 index 0000000000..c84965a6e0 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/composable_sampler_configuration_visitor.h @@ -0,0 +1,43 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class ComposableAlwaysOffSamplerConfiguration; +class ComposableAlwaysOnSamplerConfiguration; +class ComposableProbabilitySamplerConfiguration; +class ComposableParentThresholdSamplerConfiguration; +class ComposableRuleBasedSamplerConfiguration; + +class ComposableSamplerConfigurationVisitor +{ +public: + ComposableSamplerConfigurationVisitor() = default; + ComposableSamplerConfigurationVisitor(ComposableSamplerConfigurationVisitor &&) = default; + ComposableSamplerConfigurationVisitor(const ComposableSamplerConfigurationVisitor &) = default; + ComposableSamplerConfigurationVisitor &operator=(ComposableSamplerConfigurationVisitor &&) = + default; + ComposableSamplerConfigurationVisitor &operator=(const ComposableSamplerConfigurationVisitor &) = + default; + virtual ~ComposableSamplerConfigurationVisitor() = default; + + virtual void VisitComposableAlwaysOff(const ComposableAlwaysOffSamplerConfiguration *model) = 0; + virtual void VisitComposableAlwaysOn(const ComposableAlwaysOnSamplerConfiguration *model) = 0; + virtual void VisitComposableProbability( + const ComposableProbabilitySamplerConfiguration *model) = 0; + virtual void VisitComposableParentThreshold( + const ComposableParentThresholdSamplerConfiguration *model) = 0; + virtual void VisitComposableRuleBased(const ComposableRuleBasedSamplerConfiguration *model) = 0; +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/composite_sampler_configuration.h b/sdk/include/opentelemetry/sdk/configuration/composite_sampler_configuration.h new file mode 100644 index 0000000000..b399741934 --- /dev/null +++ b/sdk/include/opentelemetry/sdk/configuration/composite_sampler_configuration.h @@ -0,0 +1,34 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include + +#include "opentelemetry/sdk/configuration/composable_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/sampler_configuration.h" +#include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" +#include "opentelemetry/version.h" + +OPENTELEMETRY_BEGIN_NAMESPACE +namespace sdk +{ +namespace configuration +{ + +class CompositeSamplerConfiguration : public SamplerConfiguration +{ +public: + CompositeSamplerConfiguration() = default; + + std::unique_ptr composable_sampler; + + void Accept(SamplerConfigurationVisitor *visitor) const override + { + visitor->VisitComposite(this); + } +}; + +} // namespace configuration +} // namespace sdk +OPENTELEMETRY_END_NAMESPACE diff --git a/sdk/include/opentelemetry/sdk/configuration/sampler_configuration_visitor.h b/sdk/include/opentelemetry/sdk/configuration/sampler_configuration_visitor.h index 5c5aca24b4..48d8de49ba 100644 --- a/sdk/include/opentelemetry/sdk/configuration/sampler_configuration_visitor.h +++ b/sdk/include/opentelemetry/sdk/configuration/sampler_configuration_visitor.h @@ -18,12 +18,7 @@ class ParentBasedSamplerConfiguration; class ProbabilitySamplerConfiguration; class TraceIdRatioBasedSamplerConfiguration; class ExtensionSamplerConfiguration; -class ComposableAlwaysOffSamplerConfiguration; -class ComposableAlwaysOnSamplerConfiguration; -class ComposableProbabilitySamplerConfiguration; -class ComposableParentThresholdSamplerConfiguration; -class ComposableRuleBasedSamplerConfiguration; -class ComposableSamplerConfiguration; +class CompositeSamplerConfiguration; class SamplerConfigurationVisitor { @@ -35,20 +30,14 @@ class SamplerConfigurationVisitor SamplerConfigurationVisitor &operator=(const SamplerConfigurationVisitor &other) = default; virtual ~SamplerConfigurationVisitor() = default; - virtual void VisitAlwaysOff(const AlwaysOffSamplerConfiguration *model) = 0; - virtual void VisitAlwaysOn(const AlwaysOnSamplerConfiguration *model) = 0; - virtual void VisitJaegerRemote(const JaegerRemoteSamplerConfiguration *model) = 0; - virtual void VisitParentBased(const ParentBasedSamplerConfiguration *model) = 0; - virtual void VisitProbability(const ProbabilitySamplerConfiguration *model) = 0; - virtual void VisitTraceIdRatioBased(const TraceIdRatioBasedSamplerConfiguration *model) = 0; - virtual void VisitExtension(const ExtensionSamplerConfiguration *model) = 0; - virtual void VisitComposableAlwaysOff(const ComposableAlwaysOffSamplerConfiguration *model) = 0; - virtual void VisitComposableAlwaysOn(const ComposableAlwaysOnSamplerConfiguration *model) = 0; - virtual void VisitComposableProbability( - const ComposableProbabilitySamplerConfiguration *model) = 0; - virtual void VisitComposableParentThreshold( - const ComposableParentThresholdSamplerConfiguration *model) = 0; - virtual void VisitComposableRuleBased(const ComposableRuleBasedSamplerConfiguration *model) = 0; + virtual void VisitAlwaysOff(const AlwaysOffSamplerConfiguration *model) = 0; + virtual void VisitAlwaysOn(const AlwaysOnSamplerConfiguration *model) = 0; + virtual void VisitJaegerRemote(const JaegerRemoteSamplerConfiguration *model) = 0; + virtual void VisitParentBased(const ParentBasedSamplerConfiguration *model) = 0; + virtual void VisitProbability(const ProbabilitySamplerConfiguration *model) = 0; + virtual void VisitTraceIdRatioBased(const TraceIdRatioBasedSamplerConfiguration *model) = 0; + virtual void VisitExtension(const ExtensionSamplerConfiguration *model) = 0; + virtual void VisitComposite(const CompositeSamplerConfiguration *model) = 0; }; } // namespace configuration diff --git a/sdk/include/opentelemetry/sdk/configuration/sdk_builder.h b/sdk/include/opentelemetry/sdk/configuration/sdk_builder.h index 7dae1952b8..07b2ef2ee1 100644 --- a/sdk/include/opentelemetry/sdk/configuration/sdk_builder.h +++ b/sdk/include/opentelemetry/sdk/configuration/sdk_builder.h @@ -76,19 +76,11 @@ class ComposableSampler; namespace configuration { -class ComposableAlwaysOffSamplerConfiguration; -class ComposableAlwaysOnSamplerConfiguration; -class ComposableParentThresholdSamplerConfiguration; -class ComposableProbabilitySamplerConfiguration; -class ComposableRuleBasedSamplerConfiguration; class ComposableSamplerConfiguration; class SdkBuilder { public: - /// Maximum nesting depth of composable samplers, root included. - static constexpr std::size_t kDefaultMaxComposableSamplerDepth = 10; - SdkBuilder(std::shared_ptr registry) : registry_(std::move(registry)) {} SdkBuilder(SdkBuilder &&) = default; SdkBuilder(const SdkBuilder &) = default; @@ -120,33 +112,6 @@ class SdkBuilder std::unique_ptr CreateSampler( const std::unique_ptr &model) const; - std::unique_ptr CreateComposableAlwaysOffSampler( - const opentelemetry::sdk::configuration::ComposableAlwaysOffSamplerConfiguration *model) - const; - - std::unique_ptr CreateComposableAlwaysOnSampler( - const opentelemetry::sdk::configuration::ComposableAlwaysOnSamplerConfiguration *model) const; - - std::unique_ptr CreateComposableProbabilitySampler( - const opentelemetry::sdk::configuration::ComposableProbabilitySamplerConfiguration *model) - const; - - std::unique_ptr - CreateComposableParentThresholdSampler( - const opentelemetry::sdk::configuration::ComposableParentThresholdSamplerConfiguration *model, - std::size_t depth = 1) const; - - std::unique_ptr CreateComposableRuleBasedSampler( - const opentelemetry::sdk::configuration::ComposableRuleBasedSamplerConfiguration *model, - std::size_t depth = 1) const; - - /// Throws UnsupportedException when depth exceeds the maximum. - std::unique_ptr CreateComposableSampler( - const opentelemetry::sdk::configuration::ComposableSamplerConfiguration *model, - std::size_t depth = 1) const; - - void SetMaxComposableSamplerDepth(std::size_t depth) { max_composable_sampler_depth_ = depth; } - std::unique_ptr CreateCompositeSampler( const opentelemetry::sdk::configuration::ComposableSamplerConfiguration *model) const; @@ -332,7 +297,6 @@ class SdkBuilder private: std::shared_ptr registry_; - std::size_t max_composable_sampler_depth_{kDefaultMaxComposableSamplerDepth}; }; } // namespace configuration diff --git a/sdk/src/configuration/composable_always_off_sampler_configuration.cc b/sdk/src/configuration/composable_always_off_sampler_configuration.cc index c0eee691a9..c7dceaedb2 100644 --- a/sdk/src/configuration/composable_always_off_sampler_configuration.cc +++ b/sdk/src/configuration/composable_always_off_sampler_configuration.cc @@ -2,14 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/sdk/configuration/composable_always_off_sampler_configuration.h" -#include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" +#include "opentelemetry/sdk/configuration/composable_sampler_configuration_visitor.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace configuration { -void ComposableAlwaysOffSamplerConfiguration::Accept(SamplerConfigurationVisitor *visitor) const +void ComposableAlwaysOffSamplerConfiguration::Accept( + ComposableSamplerConfigurationVisitor *visitor) const { visitor->VisitComposableAlwaysOff(this); } diff --git a/sdk/src/configuration/composable_always_on_sampler_configuration.cc b/sdk/src/configuration/composable_always_on_sampler_configuration.cc index 4355818800..e40d383c0c 100644 --- a/sdk/src/configuration/composable_always_on_sampler_configuration.cc +++ b/sdk/src/configuration/composable_always_on_sampler_configuration.cc @@ -2,14 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/sdk/configuration/composable_always_on_sampler_configuration.h" -#include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" +#include "opentelemetry/sdk/configuration/composable_sampler_configuration_visitor.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace configuration { -void ComposableAlwaysOnSamplerConfiguration::Accept(SamplerConfigurationVisitor *visitor) const +void ComposableAlwaysOnSamplerConfiguration::Accept( + ComposableSamplerConfigurationVisitor *visitor) const { visitor->VisitComposableAlwaysOn(this); } diff --git a/sdk/src/configuration/composable_parent_threshold_sampler_configuration.cc b/sdk/src/configuration/composable_parent_threshold_sampler_configuration.cc index 2c77a16c70..777f458305 100644 --- a/sdk/src/configuration/composable_parent_threshold_sampler_configuration.cc +++ b/sdk/src/configuration/composable_parent_threshold_sampler_configuration.cc @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/sdk/configuration/composable_parent_threshold_sampler_configuration.h" -#include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" +#include "opentelemetry/sdk/configuration/composable_sampler_configuration_visitor.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk @@ -10,7 +10,7 @@ namespace sdk namespace configuration { void ComposableParentThresholdSamplerConfiguration::Accept( - SamplerConfigurationVisitor *visitor) const + ComposableSamplerConfigurationVisitor *visitor) const { visitor->VisitComposableParentThreshold(this); } diff --git a/sdk/src/configuration/composable_probability_sampler_configuration.cc b/sdk/src/configuration/composable_probability_sampler_configuration.cc index 46fe16ecc5..db82ed31ca 100644 --- a/sdk/src/configuration/composable_probability_sampler_configuration.cc +++ b/sdk/src/configuration/composable_probability_sampler_configuration.cc @@ -2,14 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/sdk/configuration/composable_probability_sampler_configuration.h" -#include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" +#include "opentelemetry/sdk/configuration/composable_sampler_configuration_visitor.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace configuration { -void ComposableProbabilitySamplerConfiguration::Accept(SamplerConfigurationVisitor *visitor) const +void ComposableProbabilitySamplerConfiguration::Accept( + ComposableSamplerConfigurationVisitor *visitor) const { visitor->VisitComposableProbability(this); } diff --git a/sdk/src/configuration/composable_rule_based_sampler_configuration.cc b/sdk/src/configuration/composable_rule_based_sampler_configuration.cc index 2ee3cedbab..9c8626d5d5 100644 --- a/sdk/src/configuration/composable_rule_based_sampler_configuration.cc +++ b/sdk/src/configuration/composable_rule_based_sampler_configuration.cc @@ -2,14 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 #include "opentelemetry/sdk/configuration/composable_rule_based_sampler_configuration.h" -#include "opentelemetry/sdk/configuration/sampler_configuration_visitor.h" +#include "opentelemetry/sdk/configuration/composable_sampler_configuration_visitor.h" OPENTELEMETRY_BEGIN_NAMESPACE namespace sdk { namespace configuration { -void ComposableRuleBasedSamplerConfiguration::Accept(SamplerConfigurationVisitor *visitor) const +void ComposableRuleBasedSamplerConfiguration::Accept( + ComposableSamplerConfigurationVisitor *visitor) const { visitor->VisitComposableRuleBased(this); } diff --git a/sdk/src/configuration/configuration_parser.cc b/sdk/src/configuration/configuration_parser.cc index 8728607ca5..095b2eda83 100644 --- a/sdk/src/configuration/configuration_parser.cc +++ b/sdk/src/configuration/configuration_parser.cc @@ -34,6 +34,7 @@ #include "opentelemetry/sdk/configuration/composable_rule_based_sampler_rule_attribute_values_configuration.h" #include "opentelemetry/sdk/configuration/composable_rule_based_sampler_rule_configuration.h" #include "opentelemetry/sdk/configuration/composable_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/composite_sampler_configuration.h" #include "opentelemetry/sdk/configuration/configuration.h" #include "opentelemetry/sdk/configuration/configuration_parser.h" #include "opentelemetry/sdk/configuration/console_log_record_exporter_configuration.h" @@ -2114,7 +2115,9 @@ std::unique_ptr ConfigurationParser::ParseSamplerConfigura } else if (name == "composite/development") { - model = ParseComposableSamplerConfiguration(child, depth); + auto composite = std::make_unique(); + composite->composable_sampler = ParseComposableSamplerConfiguration(child, depth); + model = std::move(composite); } else { diff --git a/sdk/src/configuration/sdk_builder.cc b/sdk/src/configuration/sdk_builder.cc index aca1a016cf..f6253d7d76 100644 --- a/sdk/src/configuration/sdk_builder.cc +++ b/sdk/src/configuration/sdk_builder.cc @@ -35,18 +35,18 @@ #include "opentelemetry/sdk/configuration/boolean_attribute_value_configuration.h" #include "opentelemetry/sdk/configuration/cardinality_limits_configuration.h" #include "opentelemetry/sdk/configuration/composable_always_off_sampler_builder.h" -#include "opentelemetry/sdk/configuration/composable_always_off_sampler_configuration.h" #include "opentelemetry/sdk/configuration/composable_always_on_sampler_builder.h" #include "opentelemetry/sdk/configuration/composable_always_on_sampler_configuration.h" #include "opentelemetry/sdk/configuration/composable_parent_threshold_sampler_builder.h" #include "opentelemetry/sdk/configuration/composable_parent_threshold_sampler_configuration.h" #include "opentelemetry/sdk/configuration/composable_probability_sampler_builder.h" -#include "opentelemetry/sdk/configuration/composable_probability_sampler_configuration.h" #include "opentelemetry/sdk/configuration/composable_rule_based_sampler_builder.h" #include "opentelemetry/sdk/configuration/composable_rule_based_sampler_configuration.h" #include "opentelemetry/sdk/configuration/composable_rule_based_sampler_rule_configuration.h" #include "opentelemetry/sdk/configuration/composable_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/composable_sampler_configuration_visitor.h" #include "opentelemetry/sdk/configuration/composite_sampler_builder.h" +#include "opentelemetry/sdk/configuration/composite_sampler_configuration.h" #include "opentelemetry/sdk/configuration/configuration.h" #include "opentelemetry/sdk/configuration/configured_sdk.h" #include "opentelemetry/sdk/configuration/console_log_record_exporter_builder.h" @@ -368,10 +368,14 @@ class ResourceAttributeValueSetter }; class ComposableSamplerBuilder - : public opentelemetry::sdk::configuration::SamplerConfigurationVisitor + : public opentelemetry::sdk::configuration::ComposableSamplerConfigurationVisitor { public: - ComposableSamplerBuilder(const SdkBuilder *b, std::size_t depth) : sdk_builder_(b), depth_(depth) + // Maximum nesting depth of composable samplers, root included. + static constexpr std::size_t kMaxDepth = 10; + + ComposableSamplerBuilder(const Registry *registry, std::size_t depth) + : registry_(registry), depth_(depth) {} ComposableSamplerBuilder(ComposableSamplerBuilder &&) = delete; ComposableSamplerBuilder(const ComposableSamplerBuilder &) = delete; @@ -384,97 +388,139 @@ class ComposableSamplerBuilder // ExperimentalComposableRuleBasedSamplerRule which each may contain a // ExperimentalComposableRuleBasedSampler (See: schema/tracer_provider.yaml#L340). // Recursion is used to build the nested samplers, but the depth of recursion is limited to - // (max_composable_sampler_depth_). - // // NOLINTBEGIN(misc-no-recursion) void VisitComposableAlwaysOff( const opentelemetry::sdk::configuration::ComposableAlwaysOffSamplerConfiguration *model) override { - sampler = sdk_builder_->CreateComposableAlwaysOffSampler(model); + const ComposableAlwaysOffSamplerBuilder *builder = + registry_->GetComposableAlwaysOffSamplerBuilder(); + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("VisitComposableAlwaysOff() using registered builder"); + sampler = builder->Build(model); + return; + } + static const std::string die("No builder for ComposableAlwaysOffSampler"); + throw UnsupportedException(die); } void VisitComposableAlwaysOn( const opentelemetry::sdk::configuration::ComposableAlwaysOnSamplerConfiguration *model) override { - sampler = sdk_builder_->CreateComposableAlwaysOnSampler(model); + const ComposableAlwaysOnSamplerBuilder *builder = + registry_->GetComposableAlwaysOnSamplerBuilder(); + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("VisitComposableAlwaysOn() using registered builder"); + sampler = builder->Build(model); + return; + } + static const std::string die("No builder for ComposableAlwaysOnSampler"); + throw UnsupportedException(die); } void VisitComposableProbability( const opentelemetry::sdk::configuration::ComposableProbabilitySamplerConfiguration *model) override { - sampler = sdk_builder_->CreateComposableProbabilitySampler(model); + const ComposableProbabilitySamplerBuilder *builder = + registry_->GetComposableProbabilitySamplerBuilder(); + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("VisitComposableProbability() using registered builder"); + sampler = builder->Build(model); + return; + } + static const std::string die("No builder for ComposableProbabilitySampler"); + throw UnsupportedException(die); } void VisitComposableParentThreshold( const opentelemetry::sdk::configuration::ComposableParentThresholdSamplerConfiguration *model) override { - sampler = sdk_builder_->CreateComposableParentThresholdSampler(model, depth_); + std::unique_ptr root; + if (model->root != nullptr) + { + root = BuildChild(model->root.get()); + } + else + { + static const opentelemetry::sdk::configuration::ComposableAlwaysOnSamplerConfiguration + kAlwaysOn; + const ComposableAlwaysOnSamplerBuilder *ao_builder = + registry_->GetComposableAlwaysOnSamplerBuilder(); + if (ao_builder == nullptr) + { + static const std::string die("No builder for ComposableAlwaysOnSampler"); + throw UnsupportedException(die); + } + root = ao_builder->Build(&kAlwaysOn); + } + const ComposableParentThresholdSamplerBuilder *builder = + registry_->GetComposableParentThresholdSamplerBuilder(); + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("VisitComposableParentThreshold() using registered builder"); + sampler = builder->Build(model, std::move(root)); + return; + } + static const std::string die("No builder for ComposableParentThresholdSampler"); + throw UnsupportedException(die); } void VisitComposableRuleBased( const opentelemetry::sdk::configuration::ComposableRuleBasedSamplerConfiguration *model) override { - sampler = sdk_builder_->CreateComposableRuleBasedSampler(model, depth_); + // Index-aligned with model->rules, null for rules with no sampler. + std::vector> rule_samplers; + rule_samplers.reserve(model->rules.size()); + for (const auto &rule : model->rules) + { + if (rule == nullptr || rule->sampler == nullptr) + { + OTEL_INTERNAL_LOG_WARN("Ignoring a rule with no sampler"); + rule_samplers.push_back(nullptr); + continue; + } + rule_samplers.push_back(BuildChild(rule->sampler.get())); + } + const ComposableRuleBasedSamplerBuilder *builder = + registry_->GetComposableRuleBasedSamplerBuilder(); + if (builder != nullptr) + { + OTEL_INTERNAL_LOG_DEBUG("VisitComposableRuleBased() using registered builder"); + sampler = builder->Build(model, std::move(rule_samplers)); + return; + } + static const std::string die("No builder for ComposableRuleBasedSampler"); + throw UnsupportedException(die); } // NOLINTEND(misc-no-recursion) - // The model only ever nests ComposableSamplerConfiguration here, so the - // plain sampler visits are unreachable. Throw to preserve the invariant - // that a null sampler is never returned. - void VisitAlwaysOff( - const opentelemetry::sdk::configuration::AlwaysOffSamplerConfiguration * /* model */) override - { - throw UnsupportedException(kNotComposable); - } - - void VisitAlwaysOn( - const opentelemetry::sdk::configuration::AlwaysOnSamplerConfiguration * /* model */) override - { - throw UnsupportedException(kNotComposable); - } - - void VisitJaegerRemote(const opentelemetry::sdk::configuration::JaegerRemoteSamplerConfiguration - * /* model */) override - { - throw UnsupportedException(kNotComposable); - } - - void VisitParentBased(const opentelemetry::sdk::configuration::ParentBasedSamplerConfiguration - * /* model */) override - { - throw UnsupportedException(kNotComposable); - } - - void VisitProbability(const opentelemetry::sdk::configuration::ProbabilitySamplerConfiguration - * /* model */) override - { - throw UnsupportedException(kNotComposable); - } - - void VisitTraceIdRatioBased( - const opentelemetry::sdk::configuration::TraceIdRatioBasedSamplerConfiguration * /* model */) - override - { - throw UnsupportedException(kNotComposable); - } - - void VisitExtension( - const opentelemetry::sdk::configuration::ExtensionSamplerConfiguration * /* model */) override - { - throw UnsupportedException(kNotComposable); - } - std::unique_ptr sampler; private: - static constexpr const char *kNotComposable = "Expecting a composable sampler"; + // NOLINTBEGIN(misc-no-recursion) + std::unique_ptr BuildChild( + const opentelemetry::sdk::configuration::ComposableSamplerConfiguration *child_model) + { + if (depth_ + 1 > kMaxDepth) + { + std::string die("Composable sampler nesting depth exceeds "); + die.append(std::to_string(kMaxDepth)); + throw UnsupportedException(die); + } + ComposableSamplerBuilder child(registry_, depth_ + 1); + child_model->Accept(&child); + return std::move(child.sampler); + } + // NOLINTEND(misc-no-recursion) - const SdkBuilder *sdk_builder_; + const Registry *registry_; std::size_t depth_; }; @@ -531,39 +577,10 @@ class SamplerBuilder : public opentelemetry::sdk::configuration::SamplerConfigur sampler = sdk_builder_->CreateExtensionSampler(model); } - void VisitComposableAlwaysOff( - const opentelemetry::sdk::configuration::ComposableAlwaysOffSamplerConfiguration *model) - override - { - sampler = sdk_builder_->CreateCompositeSampler(model); - } - - void VisitComposableAlwaysOn( - const opentelemetry::sdk::configuration::ComposableAlwaysOnSamplerConfiguration *model) - override + void VisitComposite( + const opentelemetry::sdk::configuration::CompositeSamplerConfiguration *model) override { - sampler = sdk_builder_->CreateCompositeSampler(model); - } - - void VisitComposableProbability( - const opentelemetry::sdk::configuration::ComposableProbabilitySamplerConfiguration *model) - override - { - sampler = sdk_builder_->CreateCompositeSampler(model); - } - - void VisitComposableParentThreshold( - const opentelemetry::sdk::configuration::ComposableParentThresholdSamplerConfiguration *model) - override - { - sampler = sdk_builder_->CreateCompositeSampler(model); - } - - void VisitComposableRuleBased( - const opentelemetry::sdk::configuration::ComposableRuleBasedSamplerConfiguration *model) - override - { - sampler = sdk_builder_->CreateCompositeSampler(model); + sampler = sdk_builder_->CreateCompositeSampler(model->composable_sampler.get()); } std::unique_ptr sampler; @@ -1024,126 +1041,7 @@ std::unique_ptr SdkBuilder::CreateParentBase throw UnsupportedException(die); } -std::unique_ptr -SdkBuilder::CreateComposableAlwaysOffSampler( - const opentelemetry::sdk::configuration::ComposableAlwaysOffSamplerConfiguration *model) const -{ - const ComposableAlwaysOffSamplerBuilder *builder = - registry_->GetComposableAlwaysOffSamplerBuilder(); - if (builder != nullptr) - { - OTEL_INTERNAL_LOG_DEBUG("CreateComposableAlwaysOffSampler() using registered builder"); - return builder->Build(model); - } - static const std::string die("No builder for ComposableAlwaysOffSampler"); - throw UnsupportedException(die); -} - -std::unique_ptr -SdkBuilder::CreateComposableAlwaysOnSampler( - const opentelemetry::sdk::configuration::ComposableAlwaysOnSamplerConfiguration *model) const -{ - const ComposableAlwaysOnSamplerBuilder *builder = - registry_->GetComposableAlwaysOnSamplerBuilder(); - if (builder != nullptr) - { - OTEL_INTERNAL_LOG_DEBUG("CreateComposableAlwaysOnSampler() using registered builder"); - return builder->Build(model); - } - static const std::string die("No builder for ComposableAlwaysOnSampler"); - throw UnsupportedException(die); -} - -std::unique_ptr -SdkBuilder::CreateComposableProbabilitySampler( - const opentelemetry::sdk::configuration::ComposableProbabilitySamplerConfiguration *model) const -{ - const ComposableProbabilitySamplerBuilder *builder = - registry_->GetComposableProbabilitySamplerBuilder(); - if (builder != nullptr) - { - OTEL_INTERNAL_LOG_DEBUG("CreateComposableProbabilitySampler() using registered builder"); - return builder->Build(model); - } - static const std::string die("No builder for ComposableProbabilitySampler"); - throw UnsupportedException(die); -} - // NOLINTBEGIN(misc-no-recursion) -std::unique_ptr -SdkBuilder::CreateComposableParentThresholdSampler( - const opentelemetry::sdk::configuration::ComposableParentThresholdSamplerConfiguration *model, - std::size_t depth) const -{ - std::unique_ptr root; - if (model->root != nullptr) - { - root = CreateComposableSampler(model->root.get(), depth + 1); - } - else - { - static const opentelemetry::sdk::configuration::ComposableAlwaysOnSamplerConfiguration - kAlwaysOn; - root = CreateComposableAlwaysOnSampler(&kAlwaysOn); - } - - const ComposableParentThresholdSamplerBuilder *builder = - registry_->GetComposableParentThresholdSamplerBuilder(); - if (builder != nullptr) - { - OTEL_INTERNAL_LOG_DEBUG("CreateComposableParentThresholdSampler() using registered builder"); - return builder->Build(model, std::move(root)); - } - static const std::string die("No builder for ComposableParentThresholdSampler"); - throw UnsupportedException(die); -} - -std::unique_ptr -SdkBuilder::CreateComposableRuleBasedSampler( - const opentelemetry::sdk::configuration::ComposableRuleBasedSamplerConfiguration *model, - std::size_t depth) const -{ - // Index-aligned with model->rules, null for rules with no sampler. - std::vector> rule_samplers; - rule_samplers.reserve(model->rules.size()); - for (const auto &rule : model->rules) - { - if (rule == nullptr || rule->sampler == nullptr) - { - OTEL_INTERNAL_LOG_WARN("Ignoring a rule with no sampler"); - rule_samplers.push_back(nullptr); - continue; - } - rule_samplers.push_back(CreateComposableSampler(rule->sampler.get(), depth + 1)); - } - - const ComposableRuleBasedSamplerBuilder *builder = - registry_->GetComposableRuleBasedSamplerBuilder(); - if (builder != nullptr) - { - OTEL_INTERNAL_LOG_DEBUG("CreateComposableRuleBasedSampler() using registered builder"); - return builder->Build(model, std::move(rule_samplers)); - } - static const std::string die("No builder for ComposableRuleBasedSampler"); - throw UnsupportedException(die); -} - -std::unique_ptr SdkBuilder::CreateComposableSampler( - const opentelemetry::sdk::configuration::ComposableSamplerConfiguration *model, - std::size_t depth) const -{ - if (depth > max_composable_sampler_depth_) - { - std::string die("Composable sampler nesting depth exceeds "); - die.append(std::to_string(max_composable_sampler_depth_)); - throw UnsupportedException(die); - } - ComposableSamplerBuilder builder(this, depth); - model->Accept(&builder); - return std::move(builder.sampler); -} -// NOLINTEND(misc-no-recursion) - std::unique_ptr SdkBuilder::CreateCompositeSampler( const opentelemetry::sdk::configuration::ComposableSamplerConfiguration *model) const { @@ -1151,11 +1049,14 @@ std::unique_ptr SdkBuilder::CreateCompositeS if (builder != nullptr) { OTEL_INTERNAL_LOG_DEBUG("CreateCompositeSampler() using registered builder"); - return builder->Build(CreateComposableSampler(model)); + ComposableSamplerBuilder composable_builder(registry_.get(), 1); + model->Accept(&composable_builder); + return builder->Build(std::move(composable_builder.sampler)); } static const std::string die("No builder for CompositeSampler"); throw UnsupportedException(die); } +// NOLINTEND(misc-no-recursion) std::unique_ptr SdkBuilder::CreateProbabilitySampler( const opentelemetry::sdk::configuration::ProbabilitySamplerConfiguration *model) const diff --git a/sdk/test/configuration/sdk_builder_test.cc b/sdk/test/configuration/sdk_builder_test.cc index 735bb36a4a..9c908fb458 100644 --- a/sdk/test/configuration/sdk_builder_test.cc +++ b/sdk/test/configuration/sdk_builder_test.cc @@ -30,6 +30,7 @@ #include "opentelemetry/sdk/configuration/composable_rule_based_sampler_rule_attribute_values_configuration.h" #include "opentelemetry/sdk/configuration/composable_rule_based_sampler_rule_configuration.h" #include "opentelemetry/sdk/configuration/composable_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/composite_sampler_configuration.h" #include "opentelemetry/sdk/configuration/extension_push_metric_exporter_builder.h" #include "opentelemetry/sdk/configuration/extension_push_metric_exporter_configuration.h" #include "opentelemetry/sdk/configuration/instrument_type.h" @@ -123,7 +124,9 @@ std::unique_ptr BuildRuleSampler( rule->sampler = std::make_unique(); auto rule_based_config = std::make_unique(); rule_based_config->rules.push_back(std::move(rule)); - std::unique_ptr sampler_config = std::move(rule_based_config); + auto composite = std::make_unique(); + composite->composable_sampler = std::move(rule_based_config); + std::unique_ptr sampler_config = std::move(composite); config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); return builder.CreateSampler(sampler_config); } @@ -341,7 +344,9 @@ TEST(SdkBuilder, CreateProbabilitySampler) TEST(SdkBuilder, CreateComposableAlwaysOnSampler) { auto composable_config = std::make_unique(); - std::unique_ptr sampler_config = std::move(composable_config); + auto composite = std::make_unique(); + composite->composable_sampler = std::move(composable_config); + std::unique_ptr sampler_config = std::move(composite); config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateSampler(sampler_config); ASSERT_NE(sampler, nullptr); @@ -352,7 +357,9 @@ TEST(SdkBuilder, CreateComposableAlwaysOnSampler) TEST(SdkBuilder, CreateComposableAlwaysOffSampler) { auto composable_config = std::make_unique(); - std::unique_ptr sampler_config = std::move(composable_config); + auto composite = std::make_unique(); + composite->composable_sampler = std::move(composable_config); + std::unique_ptr sampler_config = std::move(composite); config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateSampler(sampler_config); ASSERT_NE(sampler, nullptr); @@ -365,8 +372,9 @@ TEST(SdkBuilder, CreateComposableProbabilitySampler) auto composable_probability_sampler_config = std::make_unique(); composable_probability_sampler_config->ratio = 0.25; - std::unique_ptr sampler_config = - std::move(composable_probability_sampler_config); + auto composite = std::make_unique(); + composite->composable_sampler = std::move(composable_probability_sampler_config); + std::unique_ptr sampler_config = std::move(composite); config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateSampler(sampler_config); ASSERT_NE(sampler, nullptr); @@ -380,8 +388,10 @@ TEST(SdkBuilder, CreateComposableParentThresholdSampler) root_config->ratio = 0.25; auto parent_config = std::make_unique(); - parent_config->root = std::move(root_config); - std::unique_ptr sampler_config = std::move(parent_config); + parent_config->root = std::move(root_config); + auto composite = std::make_unique(); + composite->composable_sampler = std::move(parent_config); + std::unique_ptr sampler_config = std::move(composite); config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateSampler(sampler_config); ASSERT_NE(sampler, nullptr); @@ -394,8 +404,10 @@ TEST(SdkBuilder, CreateComposableParentThresholdSamplerNullRoot) { auto parent_config = std::make_unique(); - parent_config->root = nullptr; - std::unique_ptr sampler_config = std::move(parent_config); + parent_config->root = nullptr; + auto composite = std::make_unique(); + composite->composable_sampler = std::move(parent_config); + std::unique_ptr sampler_config = std::move(composite); config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateSampler(sampler_config); ASSERT_NE(sampler, nullptr); @@ -413,9 +425,10 @@ TEST(SdkBuilder, CreateComposableParentThresholdSamplerNestedDepth3) middle_config->root = std::move(innermost_config); auto outer_config = std::make_unique(); - outer_config->root = std::move(middle_config); - - std::unique_ptr sampler_config = std::move(outer_config); + outer_config->root = std::move(middle_config); + auto composite = std::make_unique(); + composite->composable_sampler = std::move(outer_config); + std::unique_ptr sampler_config = std::move(composite); config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateSampler(sampler_config); ASSERT_NE(sampler, nullptr); @@ -440,7 +453,9 @@ std::unique_ptr MakeNestedComposableConfig( parent->root = std::move(node); node = std::move(parent); } - return node; + auto composite = std::make_unique(); + composite->composable_sampler = std::move(node); + return composite; } } // namespace @@ -448,8 +463,7 @@ std::unique_ptr MakeNestedComposableConfig( TEST(SdkBuilder, CreateComposableSamplerAtMaxDepth) { // 9 parent nodes + leaf = depth 10, the default maximum. - auto sampler_config = - MakeNestedComposableConfig(config_sdk::SdkBuilder::kDefaultMaxComposableSamplerDepth - 1); + auto sampler_config = MakeNestedComposableConfig(9); config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateSampler(sampler_config); ASSERT_NE(sampler, nullptr); @@ -458,25 +472,11 @@ TEST(SdkBuilder, CreateComposableSamplerAtMaxDepth) TEST(SdkBuilder, CreateComposableSamplerBeyondMaxDepth) { // 10 parent nodes + leaf = depth 11, exceeding the default maximum. - auto sampler_config = - MakeNestedComposableConfig(config_sdk::SdkBuilder::kDefaultMaxComposableSamplerDepth); + auto sampler_config = MakeNestedComposableConfig(10); config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); EXPECT_THROW(builder.CreateSampler(sampler_config), config_sdk::UnsupportedException); } -TEST(SdkBuilder, SetMaxComposableSamplerDepth) -{ - // 2 parent nodes + leaf = depth 3. - auto sampler_config = MakeNestedComposableConfig(2); - config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); - builder.SetMaxComposableSamplerDepth(2); - EXPECT_THROW(builder.CreateSampler(sampler_config), config_sdk::UnsupportedException); - - auto sampler_config_ok = MakeNestedComposableConfig(1); - auto sampler = builder.CreateSampler(sampler_config_ok); - ASSERT_NE(sampler, nullptr); -} - TEST(SdkBuilder, CreateComposableRuleBasedSampler) { auto rule_based_config = std::make_unique(); @@ -493,8 +493,9 @@ TEST(SdkBuilder, CreateComposableRuleBasedSampler) auto fallback = std::make_unique(); fallback->sampler = std::make_unique(); rule_based_config->rules.push_back(std::move(fallback)); - - std::unique_ptr sampler_config = std::move(rule_based_config); + auto composite = std::make_unique(); + composite->composable_sampler = std::move(rule_based_config); + std::unique_ptr sampler_config = std::move(composite); config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateSampler(sampler_config); ASSERT_NE(sampler, nullptr); @@ -729,7 +730,9 @@ TEST(SdkBuilder, RuleBasedFirstMatchAndDefaults) auto second = std::make_unique(); second->sampler = std::make_unique(); rule_based_config->rules.push_back(std::move(second)); - std::unique_ptr sampler_config = std::move(rule_based_config); + auto composite = std::make_unique(); + composite->composable_sampler = std::move(rule_based_config); + std::unique_ptr sampler_config = std::move(composite); config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateSampler(sampler_config); ASSERT_NE(sampler, nullptr); @@ -741,7 +744,9 @@ TEST(SdkBuilder, RuleBasedFirstMatchAndDefaults) { auto rule_based_config = std::make_unique(); - std::unique_ptr sampler_config = std::move(rule_based_config); + auto composite = std::make_unique(); + composite->composable_sampler = std::move(rule_based_config); + std::unique_ptr sampler_config = std::move(composite); config_sdk::SdkBuilder builder(config_sdk::RegistryFactory::Create()); auto sampler = builder.CreateSampler(sampler_config); ASSERT_NE(sampler, nullptr); diff --git a/sdk/test/configuration/yaml_trace_test.cc b/sdk/test/configuration/yaml_trace_test.cc index d02af743be..9ecce9ca34 100644 --- a/sdk/test/configuration/yaml_trace_test.cc +++ b/sdk/test/configuration/yaml_trace_test.cc @@ -14,6 +14,9 @@ #include "opentelemetry/sdk/configuration/composable_rule_based_sampler_rule_attribute_patterns_configuration.h" #include "opentelemetry/sdk/configuration/composable_rule_based_sampler_rule_attribute_values_configuration.h" #include "opentelemetry/sdk/configuration/composable_rule_based_sampler_rule_configuration.h" +#include "opentelemetry/sdk/configuration/composable_sampler_configuration.h" +#include "opentelemetry/sdk/configuration/composable_sampler_configuration_visitor.h" +#include "opentelemetry/sdk/configuration/composite_sampler_configuration.h" #include "opentelemetry/sdk/configuration/configuration.h" #include "opentelemetry/sdk/configuration/grpc_tls_configuration.h" #include "opentelemetry/sdk/configuration/headers_configuration.h" @@ -61,6 +64,43 @@ enum class SamplerType : std::uint8_t kProbability = 11 }; +class TestComposableSamplerVisitor + : public opentelemetry::sdk::configuration::ComposableSamplerConfigurationVisitor +{ +public: + SamplerType type_matched = SamplerType::kUnmatched; + double ratio = -1.0; + + void VisitComposableAlwaysOff( + const opentelemetry::sdk::configuration::ComposableAlwaysOffSamplerConfiguration *) override + { + type_matched = SamplerType::kComposableAlwaysOff; + } + void VisitComposableAlwaysOn( + const opentelemetry::sdk::configuration::ComposableAlwaysOnSamplerConfiguration *) override + { + type_matched = SamplerType::kComposableAlwaysOn; + } + void VisitComposableProbability( + const opentelemetry::sdk::configuration::ComposableProbabilitySamplerConfiguration *model) + override + { + type_matched = SamplerType::kComposableProbability; + ratio = model->ratio; + } + void VisitComposableParentThreshold( + const opentelemetry::sdk::configuration::ComposableParentThresholdSamplerConfiguration *) + override + { + type_matched = SamplerType::kComposableParentThreshold; + } + void VisitComposableRuleBased( + const opentelemetry::sdk::configuration::ComposableRuleBasedSamplerConfiguration *) override + { + type_matched = SamplerType::kComposableRuleBased; + } +}; + class TestSamplerVisitor : public opentelemetry::sdk::configuration::SamplerConfigurationVisitor { public: @@ -104,33 +144,13 @@ class TestSamplerVisitor : public opentelemetry::sdk::configuration::SamplerConf const opentelemetry::sdk::configuration::ExtensionSamplerConfiguration *) override {} - void VisitComposableAlwaysOff( - const opentelemetry::sdk::configuration::ComposableAlwaysOffSamplerConfiguration *) override - { - type_matched = SamplerType::kComposableAlwaysOff; - } - void VisitComposableAlwaysOn( - const opentelemetry::sdk::configuration::ComposableAlwaysOnSamplerConfiguration *) override - { - type_matched = SamplerType::kComposableAlwaysOn; - } - void VisitComposableProbability( - const opentelemetry::sdk::configuration::ComposableProbabilitySamplerConfiguration *model) - override + void VisitComposite( + const opentelemetry::sdk::configuration::CompositeSamplerConfiguration *model) override { - type_matched = SamplerType::kComposableProbability; - ratio = model->ratio; - } - void VisitComposableParentThreshold( - const opentelemetry::sdk::configuration::ComposableParentThresholdSamplerConfiguration *) - override - { - type_matched = SamplerType::kComposableParentThreshold; - } - void VisitComposableRuleBased( - const opentelemetry::sdk::configuration::ComposableRuleBasedSamplerConfiguration *) override - { - type_matched = SamplerType::kComposableRuleBased; + TestComposableSamplerVisitor composable_visitor; + model->composable_sampler->Accept(&composable_visitor); + type_matched = composable_visitor.type_matched; + ratio = composable_visitor.ratio; } }; } // namespace @@ -1374,9 +1394,12 @@ file_format: "1.0-trace" config->tracer_provider->sampler->Accept(&visitor); ASSERT_EQ(visitor.type_matched, SamplerType::kComposableRuleBased); + auto *composite = static_cast( + config->tracer_provider->sampler.get()); + ASSERT_NE(composite, nullptr); auto *rule_based_sampler = static_cast( - config->tracer_provider->sampler.get()); + composite->composable_sampler.get()); ASSERT_NE(rule_based_sampler, nullptr); ASSERT_EQ(rule_based_sampler->rules.size(), 1); From ebe7b0816ea0e0c22427d260960b9d5b6f3a1266 Mon Sep 17 00:00:00 2001 From: Douglas Barker Date: Mon, 10 Aug 2026 21:59:56 -0400 Subject: [PATCH 20/20] fix iwyu warning after merge --- sdk/test/configuration/sdk_builder_test.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sdk/test/configuration/sdk_builder_test.cc b/sdk/test/configuration/sdk_builder_test.cc index 5d6016dc45..242ddc4049 100644 --- a/sdk/test/configuration/sdk_builder_test.cc +++ b/sdk/test/configuration/sdk_builder_test.cc @@ -82,10 +82,6 @@ #include "opentelemetry/trace/trace_flags.h" #include "opentelemetry/trace/trace_id.h" -#if OPENTELEMETRY_ABI_VERSION_NO < 2 -# include "opentelemetry/sdk/configuration/unsupported_exception.h" -#endif - using opentelemetry::sdk::configuration::Registry; using opentelemetry::sdk::configuration::RegistryFactory; using opentelemetry::sdk::configuration::SdkBuilder;