Skip to content

opentelemetry-sdk: activate instrumentors from declarative config#5372

Open
ocelotl wants to merge 12 commits into
open-telemetry:mainfrom
ocelotl:issue_5361
Open

opentelemetry-sdk: activate instrumentors from declarative config#5372
ocelotl wants to merge 12 commits into
open-telemetry:mainfrom
ocelotl:issue_5361

Conversation

@ocelotl

@ocelotl ocelotl commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #5361

Summary

  • Adds configure_instrumentation() that reads instrumentation/development.python from a declarative config file and activates each listed instrumentor via the opentelemetry_instrumentor entry point group
  • Instruments are called with instrument(**opts) from the YAML; enabled: false suppresses a library without error
  • If an instrumentor class exposes a configuration attribute, opts are run through _dict_to_dataclass — the same type-coercion pipeline used for SDK component configuration — before being forwarded to instrument(); instrumentors without configuration receive opts unchanged (backwards compatible)
  • Normalizes /_ in YAML keys before dataclass field lookup so schema keys like otlp_file/development map correctly to Python field names
  • Wires configure_instrumentation() into configure_sdk()

Test plan

  • opentelemetry-sdk/tests/_configuration/test_instrumentation.py covers: no-op on missing config, unknown instrumentor warning, opts forwarding, enabled: false, multiple instrumentors, failure isolation, configuration coercion, None-field omission, unknown field rejection
  • Run pytest opentelemetry-sdk/tests/_configuration/test_instrumentation.py

@MikeGoldsmith MikeGoldsmith left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start @ocelotl - thanks.

Comment thread opentelemetry-sdk/src/opentelemetry/sdk/_configuration/instrumentation.py Outdated
Comment thread opentelemetry-sdk/src/opentelemetry/sdk/_configuration/instrumentation.py Outdated
@github-project-automation github-project-automation Bot moved this to Reviewed PRs that need fixes in Python PR digest Jul 1, 2026
@MikeGoldsmith MikeGoldsmith added the config Issues and PRs related to implementing Declarative Config label Jul 1, 2026
ocelotl added 10 commits July 3, 2026 08:49
…g 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 open-telemetry#5361

Assisted-by: Claude Sonnet 4.6
…ass 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.
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.
- 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
ocelotl added 2 commits July 3, 2026 09:24
- 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
@ocelotl ocelotl requested a review from MikeGoldsmith July 3, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config Issues and PRs related to implementing Declarative Config

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.

Declarative configuration: support for the language-specific declarative instrumentation configuration

2 participants