feat(config): add host resource detector support for declarative config#5002
Merged
xrmx merged 29 commits intoopen-telemetry:mainfrom Apr 8, 2026
Merged
Conversation
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
… into mike/config-resource-propagator
…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
e6f82a7 to
37fd26d
Compare
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
37fd26d to
fccc0ce
Compare
MikeGoldsmith
added a commit
to MikeGoldsmith/opentelemetry-python
that referenced
this pull request
Mar 20, 2026
Assisted-by: Claude Sonnet 4.6
Assisted-by: Claude Sonnet 4.6
Makes _HostResourceDetector public as HostResourceDetector and wires it to detection_development.detectors[].host in _run_detectors(). Assisted-by: Claude Sonnet 4.6
Assisted-by: Claude Sonnet 4.6
3d9ff99 to
a1166ea
Compare
…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
Assisted-by: Claude Sonnet 4.6
tammy-baylis-swi
approved these changes
Mar 30, 2026
1 task
Assisted-by: Claude Sonnet 4.6
aabmass
approved these changes
Apr 3, 2026
Assisted-by: Claude Sonnet 4.6
Assisted-by: Claude Sonnet 4.6
xrmx
reviewed
Apr 8, 2026
xrmx
reviewed
Apr 8, 2026
xrmx
approved these changes
Apr 8, 2026
xrmx
reviewed
Apr 8, 2026
xrmx
reviewed
Apr 8, 2026
xrmx
reviewed
Apr 8, 2026
xrmx
reviewed
Apr 8, 2026
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
22 tasks
chimchim89
pushed a commit
to chimchim89/opentelemetry-python
that referenced
this pull request
Apr 15, 2026
…ig (open-telemetry#5002) * config: add resource and propagator creation from declarative config 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 * update changelog with PR number Assisted-by: Claude Sonnet 4.6 * fix pylint, pyright and ruff errors in resource/propagator config - _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 * address review feedback: use _DEFAULT_RESOURCE, fix bool_array coercion - 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 * fix linter * address review feedback: single coercion table, simplify attributes merge - 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 * use Callable type annotation on _array helper Assisted-by: Claude Sonnet 4.6 * add detection infrastructure foundations for resource detectors 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 * move service.name default into base resource 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 * remove unused logging import from _propagator.py Assisted-by: Claude Sonnet 4.6 * wire host resource detector in declarative config Makes _HostResourceDetector public as HostResourceDetector and wires it to detection_development.detectors[].host in _run_detectors(). Assisted-by: Claude Sonnet 4.6 * add changelog entry for host resource detector (open-telemetry#5002) Assisted-by: Claude Sonnet 4.6 * fix import sort in test_resources.py (ruff) Assisted-by: Claude Sonnet 4.6 * revert HostResourceDetector to private _HostResourceDetector Assisted-by: Claude Sonnet 4.6 * Apply suggestion from @xrmx * Update test_resources.py * Update _resource.py --------- Co-authored-by: Aaron Abbott <aaronabbott@google.com> Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Implements
hostresource detector support increate_resource()for the declarative configuration pipeline, as part of the ongoing work tracked in the following PRs:What's included
_HostResourceDetectorpublic asHostResourceDetectordetection_development.detectors[].hostin the config toHostResourceDetectorvia_run_detectors()HostResourceDetectoronly runs when explicitly listed underdetection_development.detectorsin the configdetection_development.attributesinclude/exclude glob filter (shared infrastructure from feat(config): add resource and propagator creation from declarative config #4979)attributesalways take priority over detector-produced valuesType of change
How Has This Been Tested?
tests/_configuration/test_resource.pydetection_developmentordetectorsis absentDoes This PR Require a Contrib Repo Change?
Checklist:
Assisted-by: Claude Sonnet 4.6