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

Abierto
#5,126 2 comentarios 1 reacción 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
python
Área
backend

Línea de trabajo

Comienza con _initialize_components() en opentelemetry/sdk/_configuration/init.py y las factories específicas de cada señal _tracer_provider.py, _logger_provider.py, _meter_provider.py, _propagator.py y _resource.py. Rastrea los puntos de extensión existentes de _OTelSDKConfigurator y _BaseConfigurator antes de definir el alcance incremental. Se considera terminado cuando la ruta declarativa tenga un punto de entrada configure_sdk() compartido, preservando el comportamiento existente de los constructores y la compatibilidad con las distros.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
Python
Estrellas
2.7k
Forks
1.1k
Merge medio
3 d 12 h
PR fusionados (30 d)
16

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de open-telemetry/opentelemetry-python

Todos los issues de open-telemetry/opentelemetry-python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.