Skip to content

Support Programmatic Configuration without YAML dependencies #4134

@dbarker

Description

@dbarker

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: programmatic configuration components only. sdk_builder.cc,
      configured_sdk.cc, registry.cc, and component builders.
    • opentelemetry_configuration_yaml: yaml configuration components. yaml_configuration_parser.cc,
      ryml_document.cc, ryml_document_node.cc, and the ryml::ryml
      dependency.
  2. Build opentelemetry_configuration (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();

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussTo discuss in SIG meetingtriage/acceptedIndicates an issue or PR is ready to be actively worked on.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions