Commit 06dfb75
fix(import-checker): probe opentelemetry.trace, not the bare namespace
`opentelemetry` is a PEP 420 native namespace package — any
`opentelemetry-instrumentation-*` package creates the directory even when
`opentelemetry-api` is absent. `find_spec("opentelemetry")` then returns
non-None and `is_otel_installed` becomes True; the lazy
`from opentelemetry import trace` in `_emit_event` subsequently raises
ImportError mid-request.
`find_spec("opentelemetry.trace")` would fix the false-positive but causes
CPython to load the opentelemetry namespace package into sys.modules as a
side-effect of resolving the submodule, breaking the transitive-import
isolation guarantee enforced by test_optional_extras_isolation.py.
Use `importlib.metadata.distribution("opentelemetry-api")` instead — it
probes the package registry directly with no sys.modules side-effects, and
raises PackageNotFoundError when the api package is absent. The check is
now cheap and correct under every install permutation we can construct.
The new test source-checks the probe target so a future revert to
find_spec trips the regression guard, even though live distribution() calls
succeed either way under --all-extras.
Closes audit Low finding (import_checker.py:8) from
planning/audit/2026-06-07-deep-audit.md.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 920859f commit 06dfb75
2 files changed
Lines changed: 45 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
56 | 58 | | |
57 | 59 | | |
58 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
0 commit comments