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

未关闭
#5,126 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
冷清
技术栈
python
领域
backend

调研方向

从 opentelemetry/sdk/_configuration/init.py 中的 _initialize_components() 以及特定 signal 的工厂 _tracer_provider.py、_logger_provider.py、_meter_provider.py、_propagator.py 和 _resource.py 开始。在定义增量范围之前,先跟踪现有的 _OTelSDKConfigurator 和 _BaseConfigurator 扩展点。完成的标准是:声明式路径具有一个共享的 configure_sdk() 入口点,同时保留现有的构造函数行为和 distro 兼容性。

由索引模型根据 Issue 内容生成。

描述

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
主要语言
Python
星标
2.7k
派生
1.1k
平均合并
3 天 12 小时
30 天内合并 PR
16

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

open-telemetry/opentelemetry-python 的其他 Issue

查看 open-telemetry/opentelemetry-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。