Commit 6faa58c
feat(config): add host resource detector support for declarative config (#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 (#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>1 parent c0cbfbd commit 6faa58c
File tree
3 files changed
+82
-0
lines changed- opentelemetry-sdk
- src/opentelemetry/sdk/_configuration
- tests/_configuration
3 files changed
+82
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
151 | 152 | | |
152 | 153 | | |
153 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
154 | 158 | | |
155 | 159 | | |
156 | 160 | | |
| |||
175 | 179 | | |
176 | 180 | | |
177 | 181 | | |
| 182 | + | |
178 | 183 | | |
179 | 184 | | |
180 | 185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| 32 | + | |
| 33 | + | |
30 | 34 | | |
31 | 35 | | |
32 | 36 | | |
| |||
303 | 307 | | |
304 | 308 | | |
305 | 309 | | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
306 | 381 | | |
307 | 382 | | |
308 | 383 | | |
| |||
0 commit comments