Commit c0cbfbd
authored
feat(config): wire container resource detector via entry point loading (#5004)
* 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 container resource detector in declarative config
When `resource.detection_development.detectors[].container` is set in
the config file, attempt to use `ContainerResourceDetector` from the
`opentelemetry-resource-detector-containerid` contrib package. Unlike
the process, host, and service detectors which are implemented in the
core SDK, container detection is not available in core. Rather than
adding a hard dependency on the contrib package, we use a lazy import:
if the package is installed it is used transparently; if absent a
warning is logged with an actionable install instruction.
This mirrors the approach taken by other SDKs: JS explicitly skips
container detection when no implementation is available, and PHP also
defers container detection to a contrib package.
See: open-telemetry/opentelemetry-configuration#570
Assisted-by: Claude Sonnet 4.6
* add changelog entry for container resource detector (#5004)
Assisted-by: Claude Sonnet 4.6
* add pylint disables for lazy container import in _resource.py
Assisted-by: Claude Sonnet 4.6
* load container detector via entry point instead of lazy import
Matches the env-var config counterpart (OTEL_EXPERIMENTAL_RESOURCE_DETECTORS)
and avoids a hard import dependency on the contrib package. Tests updated
to mock entry_points instead of sys.modules.
Assisted-by: Claude Sonnet 4.61 parent f764e45 commit c0cbfbd
File tree
3 files changed
+114
-1
lines changed- opentelemetry-sdk
- src/opentelemetry/sdk/_configuration
- tests/_configuration
3 files changed
+114
-1
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: 25 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
150 | 151 | | |
151 | 152 | | |
152 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
153 | 178 | | |
154 | 179 | | |
155 | 180 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
302 | 303 | | |
303 | 304 | | |
304 | 305 | | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 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 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
305 | 391 | | |
306 | 392 | | |
307 | 393 | | |
| |||
0 commit comments