Skip to content

Commit 14ba572

Browse files
committed
address review feedback: simplify resource filter and propagator loading
Assisted-by: Claude Sonnet 4.6
1 parent d7b4616 commit 14ba572

2 files changed

Lines changed: 10 additions & 17 deletions

File tree

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@
3636
def _load_entry_point_propagator(name: str) -> TextMapPropagator:
3737
"""Load a propagator by name from the opentelemetry_propagator entry point group."""
3838
try:
39-
eps = list(entry_points(group="opentelemetry_propagator", name=name))
40-
if not eps:
39+
ep = next(entry_points(group="opentelemetry_propagator", name=name), None)
40+
if not ep:
4141
raise ConfigurationError(
4242
f"Propagator '{name}' not found. "
4343
"It may not be installed or may be misspelled."
4444
)
45-
return eps[0].load()()
45+
return ep.load()()
4646
except ConfigurationError:
4747
raise
4848
except Exception as exc:
@@ -85,29 +85,24 @@ def create_propagator(
8585
if config is None:
8686
return CompositePropagator([])
8787

88-
propagators: list[TextMapPropagator] = []
89-
seen_types: set[type] = set()
90-
91-
def _add_deduped(propagator: TextMapPropagator) -> None:
92-
if type(propagator) not in seen_types:
93-
seen_types.add(type(propagator))
94-
propagators.append(propagator)
88+
propagators: dict[type[TextMapPropagator], TextMapPropagator] = {}
9589

9690
# Process structured composite list
9791
if config.composite:
9892
for entry in config.composite:
9993
for propagator in _propagators_from_textmap_config(entry):
100-
_add_deduped(propagator)
94+
propagators.setdefault(type(propagator), propagator)
10195

10296
# Process composite_list (comma-separated propagator names via entry_points)
10397
if config.composite_list:
10498
for name in config.composite_list.split(","):
10599
name = name.strip()
106100
if not name or name.lower() == "none":
107101
continue
108-
_add_deduped(_load_entry_point_propagator(name))
102+
propagator = _load_entry_point_propagator(name)
103+
propagators.setdefault(type(propagator), propagator)
109104

110-
return CompositePropagator(propagators)
105+
return CompositePropagator(list(propagators.values()))
111106

112107

113108
def configure_propagator(config: Optional[PropagatorConfig]) -> None:

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,10 @@ def _filter_attributes(
170170
if not included and not excluded:
171171
return attrs
172172

173-
effective_included = included if included else None # [] → include all
174-
175173
result: dict[str, object] = {}
176174
for key, value in attrs.items():
177-
if effective_included is not None and not any(
178-
fnmatch.fnmatch(key, pat) for pat in effective_included
175+
if included and not any(
176+
fnmatch.fnmatch(key, pat) for pat in included
179177
):
180178
continue
181179
if excluded and any(fnmatch.fnmatch(key, pat) for pat in excluded):

0 commit comments

Comments
 (0)