Skip to content

Commit 147e3f7

Browse files
Add check before iterating over dist.requires at load_instrumentor (#3168)
* Add check before iterate over dist.requires * Changelog * Add test
1 parent 3d5935f commit 147e3f7

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232

3333
- `opentelemetry-instrumentation-httpx` Fix `RequestInfo`/`ResponseInfo` type hints
3434
([#3105](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3105))
35+
- `opentelemetry-instrumentation` Fix `get_dist_dependency_conflicts` if no distribution requires
36+
([#3168](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3168))
3537

3638

3739
## Version 1.29.0/0.50b0 (2024-12-11)

opentelemetry-instrumentation/src/opentelemetry/instrumentation/dependencies.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ def get_dist_dependency_conflicts(
4747
extra = "extra"
4848
instruments = "instruments"
4949
instruments_marker = {extra: instruments}
50-
for dep in dist.requires:
51-
if extra not in dep or instruments not in dep:
52-
continue
53-
54-
req = Requirement(dep)
55-
if req.marker.evaluate(instruments_marker):
56-
instrumentation_deps.append(req)
50+
if dist.requires:
51+
for dep in dist.requires:
52+
if extra not in dep or instruments not in dep:
53+
continue
54+
55+
req = Requirement(dep)
56+
if req.marker.evaluate(instruments_marker):
57+
instrumentation_deps.append(req)
5758

5859
return get_dependency_conflicts(instrumentation_deps)
5960

opentelemetry-instrumentation/tests/test_dependencies.py

+16
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,19 @@ def requires(self):
8686
str(conflict),
8787
'DependencyConflict: requested: "test-pkg~=1.0; extra == "instruments"" but found: "None"',
8888
)
89+
90+
def test_get_dist_dependency_conflicts_requires_none(self):
91+
class MockDistribution(Distribution):
92+
def locate_file(self, path):
93+
pass
94+
95+
def read_text(self, filename):
96+
pass
97+
98+
@property
99+
def requires(self):
100+
return None
101+
102+
dist = MockDistribution()
103+
conflict = get_dist_dependency_conflicts(dist)
104+
self.assertTrue(conflict is None)

0 commit comments

Comments
 (0)