Skip to content

opentelemetry-instrumentation: add config_dataclass opt-in to BaseInstrumentor#4766

Open
ocelotl wants to merge 7 commits into
open-telemetry:mainfrom
ocelotl:issue_4765
Open

opentelemetry-instrumentation: add config_dataclass opt-in to BaseInstrumentor#4766
ocelotl wants to merge 7 commits into
open-telemetry:mainfrom
ocelotl:issue_4765

Conversation

@ocelotl

@ocelotl ocelotl commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #4765

Summary

  • Adds configuration: type | None = None to BaseInstrumentor; default None leaves all existing instrumentors unaffected
  • Adds URLLib3InstrumentorConfig as the reference implementation — a typed dataclass covering the four YAML-representable options (excluded_urls, captured_request_headers, captured_response_headers, sensitive_headers); callable and SDK provider options are intentionally excluded
  • Sets configuration = URLLib3InstrumentorConfig on URLLib3Instrumentor

The SDK side that reads configuration and runs options through _dict_to_dataclass is in open-telemetry/opentelemetry-python#5372.

Test plan

  • Existing urllib3 instrumentation tests continue to pass
  • New tests cover BaseInstrumentor.configuration defaulting to None/being overridable, and URLLib3Instrumentor.configuration wiring URLLib3InstrumentorConfig
  • End-to-end: run the demo at https://github.com/ocelotl/instrumentation_configuration_demo with docker compose up; verify spans appear in output/traces.jsonl with captured headers and that /healthz requests are excluded

@ocelotl ocelotl closed this Jun 30, 2026
@ocelotl
ocelotl deleted the issue_4765 branch June 30, 2026 20:01
@ocelotl
ocelotl restored the issue_4765 branch June 30, 2026 20:27
@ocelotl ocelotl reopened this Jun 30, 2026
@ocelotl
ocelotl marked this pull request as ready for review June 30, 2026 21:11
@ocelotl
ocelotl requested a review from a team as a code owner June 30, 2026 21:11

@henry3260 henry3260 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

overall LGTM, just one nit

@emdneto emdneto moved this to Ready for review in Python PR digest Jul 21, 2026
@ocelotl
ocelotl force-pushed the issue_4765 branch 2 times, most recently from c9159d4 to dd7dbaf Compare July 22, 2026 04:42
@ocelotl
ocelotl requested a review from henry3260 July 22, 2026 04:57

@henry3260 henry3260 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

ocelotl added 7 commits July 22, 2026 15:55
…trumentor

Instrumentors can set config_dataclass to a dataclass type describing
their accepted configuration options. The SDK declarative config
pipeline uses this to validate and coerce raw YAML options through
_dict_to_dataclass before calling instrument(), applying the same
type-coercion used for SDK component configuration.

The default is None, so all existing instrumentors are unaffected.
…dataclass

Expose config_dataclass on URLLib3Instrumentor so that the SDK
declarative configuration pipeline can validate and coerce raw YAML
options before calling instrument(). The dataclass covers the four
YAML-representable options: excluded_urls, captured_request_headers,
captured_response_headers, and sensitive_headers. Callable and SDK
provider options are intentionally excluded.
Covers BaseInstrumentor.configuration defaulting to None and being
overridable on subclasses, and URLLib3Instrumentor's wiring of
URLLib3InstrumentorConfig as its configuration dataclass.
pylint's disallowed-name check rejected the field name "bar" in
test_configuration_can_be_overridden. Also adds the missing
.changelog/4766.added fragment required by the changelog check.
…rument()

Add a functional test that builds URLLib3InstrumentorConfig and calls
instrument(**dataclasses.asdict(config)), asserting excluded_urls,
captured_request_headers, captured_response_headers and sensitive_headers
each take effect. Guards the contract that every config field name matches
the corresponding instrument() keyword argument, which is otherwise read via
kwargs.get() and would be silently ignored on mismatch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

Add config_dataclass to BaseInstrumentor for declarative configuration schema support

3 participants