Skip to content

feat(config): add host resource detector support for declarative config#5002

Open
MikeGoldsmith wants to merge 17 commits intoopen-telemetry:mainfrom
MikeGoldsmith:mike/config-resource-detector-host
Open

feat(config): add host resource detector support for declarative config#5002
MikeGoldsmith wants to merge 17 commits intoopen-telemetry:mainfrom
MikeGoldsmith:mike/config-resource-detector-host

Conversation

@MikeGoldsmith
Copy link
Copy Markdown
Member

@MikeGoldsmith MikeGoldsmith commented Mar 20, 2026

Description

Implements host resource detector support in create_resource() for the declarative configuration pipeline, as part of the ongoing work tracked in the following PRs:

What's included

  • Makes _HostResourceDetector public as HostResourceDetector
  • Wires detection_development.detectors[].host in the config to HostResourceDetector via _run_detectors()
  • Detectors are opt-in: HostResourceDetector only runs when explicitly listed under detection_development.detectors in the config
  • Respects the detection_development.attributes include/exclude glob filter (shared infrastructure from feat(config): add resource and propagator creation from declarative config #4979)
  • Explicit config attributes always take priority over detector-produced values
  • 8 new tests covering detector opt-in, attribute filtering (include/exclude), explicit attribute override, and SDK defaults

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • 8 unit tests in tests/_configuration/test_resource.py
  • Includes explicit tests that the detector does not run when detection_development or detectors is absent

Does This PR Require a Contrib Repo Change?

  • Yes.
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Assisted-by: Claude Sonnet 4.6

Implements create_resource() and create_propagator()/configure_propagator()
for the declarative file configuration. Resource creation does not read
OTEL_RESOURCE_ATTRIBUTES or run any detectors (matches Java/JS SDK behavior).
Propagator configuration always calls set_global_textmap to override Python's
default tracecontext+baggage, setting a noop CompositePropagator when no
propagator is configured.

Assisted-by: Claude Sonnet 4.6
Assisted-by: Claude Sonnet 4.6
- _resource.py: refactor _coerce_attribute_value to dispatch table to
  avoid too-many-return-statements; fix short variable names k/v ->
  attr_key/attr_val; fix return type of _sdk_default_attributes to
  dict[str, str] to satisfy pyright
- _propagator.py: rename short variable names e -> exc, p -> propagator
- test_resource.py: move imports to top level; split TestCreateResource
  (25 methods) into three focused classes to satisfy too-many-public-methods
- test_propagator.py: add pylint disable for protected-access

Assisted-by: Claude Sonnet 4.6
- replace _sdk_default_attributes() with _DEFAULT_RESOURCE from resources module
- move _coerce_bool into dispatch tables for both scalar and array bool types,
  fixing a bug where bool_array with string values like "false" would coerce
  incorrectly via plain bool() (non-empty string -> True)
- add test for bool_array with string values to cover the bug

Assisted-by: Claude Sonnet 4.6
…erge

- collapse _SCALAR_COERCIONS and _ARRAY_COERCIONS into a single _COERCIONS
  dict using an _array() factory, reducing _coerce_attribute_value to two lines
- process attributes_list before attributes so explicit attributes naturally
  overwrite list entries without needing an explicit guard

Assisted-by: Claude Sonnet 4.6
@MikeGoldsmith MikeGoldsmith force-pushed the mike/config-resource-detector-host branch from e6f82a7 to 37fd26d Compare March 20, 2026 13:55
Assisted-by: Claude Sonnet 4.6
Adds _run_detectors() stub and _filter_attributes() to create_resource(),
providing the shared scaffolding for detector PRs to build on. Detectors
are opt-in: nothing runs unless explicitly listed under
detection_development.detectors in the config. The include/exclude
attribute filter mirrors other SDK behaviour.

Assisted-by: Claude Sonnet 4.6
Merges service.name=unknown_service into base before running detectors,
so detectors (e.g. service) can override it. Previously it was added to
config_attrs and merged last, which would have silently overridden any
detector-provided service.name.

Assisted-by: Claude Sonnet 4.6
@MikeGoldsmith MikeGoldsmith force-pushed the mike/config-resource-detector-host branch from 37fd26d to fccc0ce Compare March 20, 2026 14:26
MikeGoldsmith added a commit to MikeGoldsmith/opentelemetry-python that referenced this pull request Mar 20, 2026
Makes _HostResourceDetector public as HostResourceDetector and wires
it to detection_development.detectors[].host in _run_detectors().

Assisted-by: Claude Sonnet 4.6
@MikeGoldsmith MikeGoldsmith force-pushed the mike/config-resource-detector-host branch from 3d9ff99 to a1166ea Compare March 20, 2026 19:46
…tor references

- @staticmethod on _config_with_host test helper
- rename _HostResourceDetector → HostResourceDetector in test_resources.py and pyproject.toml entry point

Assisted-by: Claude Sonnet 4.6
@MikeGoldsmith MikeGoldsmith marked this pull request as ready for review March 29, 2026 16:31
@MikeGoldsmith MikeGoldsmith requested a review from a team as a code owner March 29, 2026 16:31
Assisted-by: Claude Sonnet 4.6
Assisted-by: Claude Sonnet 4.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved PRs

Development

Successfully merging this pull request may close these issues.

2 participants