Skip to content

opentelemetry-sdk: activate instrumentors from declarative config#5372

Merged
xrmx merged 16 commits into
open-telemetry:mainfrom
ocelotl:issue_5361
Jul 10, 2026
Merged

opentelemetry-sdk: activate instrumentors from declarative config#5372
xrmx merged 16 commits into
open-telemetry:mainfrom
ocelotl:issue_5361

Conversation

@ocelotl

@ocelotl ocelotl commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #5361
Fixes #5395

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

@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.

I think we need to figure the warnings for when we're trying to double activate instrumentations, but otherwise looks good - thanks @ocelotl 👍🏻

@carlosalberto

Copy link
Copy Markdown
Contributor

Symbolic approval, going in the right direction.

@xrmx xrmx enabled auto-merge July 10, 2026 08:58
@xrmx xrmx added this pull request to the merge queue Jul 10, 2026
Merged via the queue into open-telemetry:main with commit 063809f Jul 10, 2026
546 checks passed
@github-project-automation github-project-automation Bot moved this from Reviewed PRs that need fixes to Done in Python PR digest Jul 10, 2026
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: Done

6 participants