feat(config): unify declarative and env-var configuration through a shared SDK orchestrator

Offen
#5,126 2 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 2 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
35/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Ruhig
Tech-Stack
python
Bereich
backend

Rechercherichtung

Beginne mit _initialize_components() in opentelemetry/sdk/_configuration/init.py und den signalspezifischen Factories _tracer_provider.py, _logger_provider.py, _meter_provider.py, _propagator.py und _resource.py. Verfolge zunächst die Erweiterungspunkte von _OTelSDKConfigurator und _BaseConfigurator, bevor du den inkrementellen Umfang festlegst. Als abgeschlossen gilt die Arbeit, wenn der deklarative Pfad einen gemeinsamen configure_sdk()-Einstiegspunkt hat und dabei das bestehende Konstruktorverhalten sowie die Distro-Kompatibilität erhalten bleiben.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Motivation

Today there are two independent configuration paths that construct the SDK:

  1. Env-var path — _initialize_components() in opentelemetry/sdk/_configuration/__init__.py orchestrates SDK init, but env-var reading is scattered across individual SDK classes (TracerProvider, BatchSpanProcessor, Resource, MeterProvider, sampling, etc.). Each class reads its own OTEL_* vars at construction time.

  2. Declarative file path — modular create_*/configure_* factory functions per signal (_tracer_provider.py, _logger_provider.py, _meter_provider.py, _propagator.py, _resource.py), but no top-level orchestrator that ties them together.

This split means:

  • Env-var reading logic is duplicated or scattered, making it hard to maintain
  • There's no single "apply this config" entry point for the declarative path
  • The two paths can drift in behavior since they don't share construction logic

Proposal

1. Add a top-level configure_sdk(config) orchestrator

A single function that takes an OpenTelemetryConfiguration and calls all configure_* functions in the correct order:

def configure_sdk(config: OpenTelemetryConfiguration) -> None:
    resource = create_resource(config.resource)
    configure_tracer_provider(config.tracer_provider, resource)
    configure_meter_provider(config.meter_provider, resource)
    configure_logger_provider(config.logger_provider, resource)
    configure_propagator(config.propagator)
2. Add an env-var-to-config adapter

A function that reads all OTEL_* env vars and produces an OpenTelemetryConfiguration, which then flows through the same configure_sdk() path:

def load_config_from_env() -> OpenTelemetryConfiguration:
    """Read OTEL_* env vars and build an OpenTelemetryConfiguration."""
    ...
End state
YAML file → load_config_file() → OpenTelemetryConfiguration → configure_sdk()
env vars  → load_config_env()  → OpenTelemetryConfiguration → configure_sdk()

Both paths converge on the same construction logic, eliminating drift.

Considerations

  • Scattered env-var reads in constructors: BatchSpanProcessor.__init__, TracerProvider.__init__, etc. read env vars when no explicit value is passed. Changing this touches public API surface and needs careful deprecation.
  • Spec requirement: Individual components must respect env vars when no explicit config value is provided. A pure "read everything upfront" approach needs to distinguish "not configured" from "explicitly set to default".
  • Backwards compatibility: The existing _OTelSDKConfigurator / _BaseConfigurator pattern is used by distros. Any refactor needs to preserve that extension point.
  • Scope: This is a large refactor best done incrementally — start with configure_sdk() for the declarative path, then gradually migrate env-var reading.

Related

  • #3631 — declarative config tracking issue
Vorherrschende Sprache
Python
Sterne
2.7k
Forks
1.1k
Ø Merge
3 T. 12 Std.
Gemergte PRs (30 T.)
16

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus open-telemetry/opentelemetry-python

Alle Issues in open-telemetry/opentelemetry-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.