opentelemetry-sdk: activate instrumentors from declarative config (#5372)
* opentelemetry-sdk: implement instrumentation.python declarative config support Add configure_instrumentation() to activate instrumentors listed under instrumentation/development.python in a declarative config file. Each key is resolved via the opentelemetry_instrumentor entry point group and instrument(**opts) is called with the supplied options. An enabled: false value suppresses a library without raising; unknown entry points and instrumentor failures are logged without stopping the others. Wire configure_instrumentation() into configure_sdk() so the python section is applied alongside providers on the declarative config path. Fixes #5361 Assisted-by: Claude Sonnet 4.6 * opentelemetry-sdk: normalize slash in YAML keys during dict-to-dataclass conversion Schema keys like "otlp_file/development" use "/" as a namespace separator for development/experimental features. Python dataclass field names cannot contain "/" so they use "_" (e.g. "otlp_file_development"). Without normalization, the key falls through to additional_properties and triggers an entry-point lookup for "otlp_file/development" (which doesn't exist), rather than using the dedicated _create_otlp_file_development_span_exporter factory function. * opentelemetry-sdk: validate instrumentation opts via config_dataclass If an instrumentor class exposes a config_dataclass attribute, the raw YAML options are run through _dict_to_dataclass before instrument() is called. This reuses the same type-coercion pipeline used for SDK component configuration so instrumentors declare a typed dataclass schema and the SDK handles the rest. Instrumentors without config_dataclass continue to receive options unchanged, preserving backwards compatibility. * refactor: inline _coerce_opts into configure_instrumentation * refactor: rename _instrumentation to instrumentation, use from-imports, expand slash-normalization comment * changelog: add fragment for PR 5372 * fix(ci): fix pylint and ruff failures in instrumentation files - Rename walrus variable `v` to `value` (pylint C0103) - Add pylint disable=no-self-use at class level in test file (pylint R6301) - Move `instrumentation` import after `_tracer_provider` in _sdk.py (ruff I001) - Convert `import logging/dataclasses/unittest` to from-imports - Apply ruff format to reformatted lines * fix(ci): move pylint disable inside class body so it applies to methods * refactor: rename config_dataclass attribute to configuration * ci: retrigger * fix: address review comments on instrumentation declarative config - Add inspect.isclass + is_dataclass guard before using the configuration attribute, so non-dataclass values are silently ignored - Skip instrument() when the instrumentor is already active to avoid duplicate-instrumentation warnings when opentelemetry-instrument and declarative config are both in play - Add Instrumentation section to docs/sdk/configuration.rst with instrumentation/development.python YAML example - Add instrumentation/development example to the declarative-config example otel-config.yaml and README * fix: use from inspect import isclass instead of import inspect --------- Co-authored-by: Mike Goldsmith <goldsmith.mike@gmail.com> Co-authored-by: Leighton Chen <lechen@microsoft.com>
D
Diego Hurtado committed
063809f272d24d9e6b83361582cd007f0d0ecabd
Parent: 08322fd
Committed by GitHub <noreply@github.com>
on 7/10/2026, 9:02:53 AM