Commit 9c270da
feat(config): add service resource detector support for declarative config (#5003)
* 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 service resource detector in declarative config
Adds service detector support to _run_detectors(): sets a random UUID
for service.instance.id and reads OTEL_SERVICE_NAME for service.name
if set. Explicit config attributes still take priority (merged last).
Assisted-by: Claude Sonnet 4.6
* add changelog entry for service resource detector (#5003)
Assisted-by: Claude Sonnet 4.6
---------
Co-authored-by: Aaron Abbott <aaronabbott@google.com>1 parent 01a552f commit 9c270da
File tree
3 files changed
+90
-0
lines changed- opentelemetry-sdk
- src/opentelemetry/sdk/_configuration
- tests/_configuration
3 files changed
+90
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
15 | 18 | | |
16 | 19 | | |
17 | 20 | | |
| |||
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| |||
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| 33 | + | |
| 34 | + | |
31 | 35 | | |
32 | 36 | | |
33 | 37 | | |
| |||
152 | 156 | | |
153 | 157 | | |
154 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
155 | 168 | | |
156 | 169 | | |
157 | 170 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
307 | 308 | | |
308 | 309 | | |
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 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
310 | 384 | | |
311 | 385 | | |
312 | 386 | | |
| |||
0 commit comments