Commit 1a33c69
Remove importlib-metadata dependency (open-telemetry#5203)
* Remove importlib-metadata dependency
Remove the third-party importlib-metadata dependency in favor of the standard library's importlib.metadata, which is stable and available natively since Python >= 3.10.
Implements a unified, branchless caching wrapper in `opentelemetry-api` that:
- Bypasses standard `entry_points()` version-specific return type differences (SelectableGroups vs EntryPoints) by building a flat `EntryPoints` sequence directly from the low-level `distributions()` API.
- Caches all resolved entry points in-memory on the first call to avoid severe startup performance degradation caused by repeated filesystem scans in standard library `importlib.metadata` (resulting in a 37x speedup on subsequent lookups and a 2x faster cold start).
- Cleans up obsolete `importlib-metadata` and `zipp` requirements across 19 test and documentation configurations.
Assisted-by: Gemini
* Refactor importlib.metadata caching wrapper to address PR comments
- Leverage stdlib `entry_points()` directly instead of the custom `distributions()` loop, ensuring standard library's `sys.path` shadowing resolution (uniqueness filtering) is perfectly preserved.
- Map Python 3.10/3.11 `SelectableGroups` (dict-like object) to `EntryPoints` (sequence) using a compatibility helper `_as_entry_points`.
- Cache the result of the no-argument stdlib `entry_points()` call via `@cache` to eliminate redundant disk-scanning on repeated lookups.
- Add a compatibility unit test for `_as_entry_points` with dict-like input.
Assisted-by: Gemini
* Apply suggestion from @herin049
Co-authored-by: Lukas Hering <40302054+herin049@users.noreply.github.com>
* Add Sphinx RST module docstring to _importlib_metadata.py
Assisted-by: Gemini
* Undo rename of _original_entry_points_cached and document test behavior
- Revert the caching function name back to _original_entry_points_cached to
avoid unnecessary churn.
- Add a docstring to test_as_entry_points_selectable_groups_compat
explaining the normalization of Python 3.10 SelectableGroups vs 3.11+.
Assisted-by: Gemini
---------
Co-authored-by: Lukas Hering <40302054+herin049@users.noreply.github.com>
Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>1 parent 4a85110 commit 1a33c69
26 files changed
Lines changed: 135 additions & 155 deletions
File tree
- .changelog
- codegen/opentelemetry-codegen-json
- docs/getting_started/tests
- exporter
- opentelemetry-exporter-opencensus
- opentelemetry-exporter-otlp-json-common
- opentelemetry-exporter-otlp-proto-common
- opentelemetry-exporter-otlp-proto-grpc
- opentelemetry-exporter-otlp-proto-http
- opentelemetry-exporter-otlp
- opentelemetry-exporter-prometheus
- opentelemetry-exporter-zipkin-json
- opentelemetry-exporter-zipkin-proto-http
- opentelemetry-exporter-zipkin
- opentelemetry-api
- src/opentelemetry/util
- tests/util
- opentelemetry-sdk
- opentelemetry-semantic-conventions
- propagator
- opentelemetry-propagator-b3
- opentelemetry-propagator-jaeger
- shim
- opentelemetry-opencensus-shim
- opentelemetry-opentracing-shim
- tests/opentelemetry-test-utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
9 | | - | |
10 | 8 | | |
11 | 9 | | |
12 | 10 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
| |||
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
23 | | - | |
24 | 22 | | |
25 | 23 | | |
26 | 24 | | |
| |||
Lines changed: 0 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
| |||
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
14 | | - | |
15 | 13 | | |
16 | 14 | | |
17 | 15 | | |
| |||
Lines changed: 0 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
| |||
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
12 | | - | |
13 | 11 | | |
14 | 12 | | |
15 | 13 | | |
| |||
Lines changed: 0 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
| |||
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
12 | | - | |
13 | 11 | | |
14 | 12 | | |
15 | 13 | | |
| |||
Lines changed: 12 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
| |||
43 | 47 | | |
44 | 48 | | |
45 | 49 | | |
46 | | - | |
47 | | - | |
| 50 | + | |
| 51 | + | |
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
| |||
66 | 70 | | |
67 | 71 | | |
68 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
69 | 77 | | |
70 | 78 | | |
71 | 79 | | |
| |||
77 | 85 | | |
78 | 86 | | |
79 | 87 | | |
80 | | - | |
81 | | - | |
| 88 | + | |
| 89 | + | |
Lines changed: 12 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
| |||
47 | 51 | | |
48 | 52 | | |
49 | 53 | | |
50 | | - | |
51 | | - | |
| 54 | + | |
| 55 | + | |
52 | 56 | | |
53 | 57 | | |
54 | 58 | | |
| |||
70 | 74 | | |
71 | 75 | | |
72 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
73 | 81 | | |
74 | 82 | | |
75 | 83 | | |
| |||
86 | 94 | | |
87 | 95 | | |
88 | 96 | | |
89 | | - | |
90 | | - | |
| 97 | + | |
| 98 | + | |
Lines changed: 0 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
| |||
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
20 | | - | |
21 | 19 | | |
22 | 20 | | |
23 | 21 | | |
| |||
Lines changed: 0 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
| |||
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
11 | | - | |
12 | 10 | | |
13 | 11 | | |
14 | 12 | | |
| |||
0 commit comments