opentelemetry-cpp icon indicating copy to clipboard operation
opentelemetry-cpp copied to clipboard

Support Programmatic Configuration without YAML dependencies

Open dbarker opened this issue 5 months ago • 3 comments

Background

The configuration spec requires programmatic configuration of the SDK in-memory that is independent of the file format (YAML, JSON, etc.).

See https://opentelemetry.io/docs/specs/otel/configuration/#programmatic

The SDK MUST provide a programmatic interface for all configuration. This interface SHOULD be written in the language of the SDK itself. All other configuration mechanisms SHOULD be built on top of this interface.

This interface exists in sdk/<include,src>/configuration and available through the opentelemetry_configuration CMake target. This target also includes the YAML parsing components (ryml_document.cc, ryml_document_node.cc, yaml_configuration_parser.cc, and ryml dependency).

Currently there isn't a way to only use the programmatic configuration without bringing in the ryml dependency.

Proposal

Allow users to link to the programmatic configuration components independent from the YAML configuration components.

  1. Split opentelemetry_configuration into two CMake targets:

    • ~~opentelemetry_configuration~~ opentelemetry_core: programmatic configuration components only. sdk_builder.cc, configured_sdk.cc, registry.cc, and component builders.
    • ~~opentelemetry_configuration_yaml~~ opentelemetry_configuration: yaml configuration components. yaml_configuration_parser.cc, ryml_document.cc, ryml_document_node.cc, and the ryml::ryml dependency.
  2. Build ~~opentelemetry_configuration~~ opentelemetry_configuration_core (programmatic configuration) unconditionally as part of the SDK.

  3. Repurpose the existing WITH_CONFIGURATION CMake option to gate only the YAML configuration target (opentelemetry_configuration_yaml) and the ryml dependency.

  4. Optional: Remove doc_ from the Configuration class and use a default constructor. Currently Configuration holds a std::unique_ptr<Document> to keep the ryml parse tree alive for the duration of ConfigurationParser::Parse().

Example Programmatic Configuration

namespace cfg = opentelemetry::sdk::configuration;

auto model         = std::make_unique<cfg::Configuration>();

auto tp = std::make_unique<cfg::TracerProviderConfiguration>();

auto otlp_grpc_exporter      = std::make_unique<cfg::OtlpGrpcSpanExporterConfiguration>();
otlp_grpc_exporter->endpoint = "http://localhost:4317";

auto processor               = std::make_unique<cfg::SimpleSpanProcessorConfiguration>();
processor->exporter          = std::move(otlp_grpc_exporter);

tp->processors.push_back(std::move(processor));  

model->tracer_provider = std::move(tp);

auto registry = std::make_shared<cfg::Registry>();
opentelemetry::exporter::otlp::OtlpGrpcSpanBuilder::Register(registry.get()); 

auto sdk = cfg::ConfiguredSdk::Create(registry, model);

sdk->Install();

dbarker avatar Jun 07 '26 00:06 dbarker

Hi @marcalff @lalitb @dbarker @ThomsonTan ,

I've opened PR #4138 to resolve issue #4134 — splitting the opentelemetry_configuration CMake target into two separate targets so users can use programmatic configuration without pulling in the ryml dependency.

The EasyCLA check has passed. Could one of you please approve the workflow runs so CI can execute? Any feedback on the implementation is also very welcome.

Thank you!

pranitaurlam avatar Jun 07 '26 18:06 pranitaurlam

Discussed in SIG meeting, this is a change we should implement. Removing the discuss flag.

marcalff avatar Jun 16 '26 18:06 marcalff

Closing as completed by #4311

dbarker avatar Aug 03 '26 21:08 dbarker