Skip to content

Commit 8d1f3ff

Browse files
committed
address review: document single-component semantic, test first-match-wins
- Add docstring note explaining the JSON schema enforces exactly one component per config block (minProperties: 1, maxProperties: 1), and that "first match wins" is the defensive fallback if validation is bypassed - Add test documenting that when multiple built-in fields are set, the first registry match wins Assisted-by: Claude Opus 4.6
1 parent e652f7a commit 8d1f3ff

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

opentelemetry-sdk/src/opentelemetry/sdk/_configuration/_common.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ def _resolve_component(
9292
field names on ``config``), then falls back to entry point loading
9393
for plugin components found in ``config.additional_properties``.
9494
95+
The JSON schema enforces exactly one component per config block
96+
(``minProperties: 1, maxProperties: 1``). If multiple typed fields or
97+
``additional_properties`` entries are set (e.g. when schema validation
98+
is bypassed), the first registry match wins.
99+
95100
Args:
96101
config: A dataclass with ``additional_properties`` (from the
97102
``@_additional_properties`` decorator).

opentelemetry-sdk/tests/_configuration/test_common.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,13 @@ def test_plugin_not_found_raises_configuration_error(self):
361361
_resolve_component(
362362
config, self.registry, "test_group", "test component"
363363
)
364+
365+
def test_first_registry_match_wins_when_multiple_set(self):
366+
"""When multiple built-in fields are set (which the schema should
367+
prevent), the first registry match wins."""
368+
config = self.cls(builtin_a={"a": 1}, builtin_b="b")
369+
result = _resolve_component(
370+
config, self.registry, "test_group", "test component"
371+
)
372+
# builtin_a comes first in the registry dict
373+
self.assertEqual(result, ("resolved_a", {"a": 1}))

0 commit comments

Comments
 (0)