Skip to content

Remove importlib-metadata dependency#5203

Merged
xrmx merged 6 commits into
open-telemetry:mainfrom
aabmass:remove-importlib-metadata
May 14, 2026
Merged

Remove importlib-metadata dependency#5203
xrmx merged 6 commits into
open-telemetry:mainfrom
aabmass:remove-importlib-metadata

Conversation

@aabmass
Copy link
Copy Markdown
Member

@aabmass aabmass commented May 13, 2026

Description

Fixes #3234

Remove the importlib-metadata dependency in favor of the standard library's importlib.metadata. Since Python >= 3.10 is now required (#5076), importlib.metadata is stable enough and available across all supported versions.

Adds a compatibility wrapper in opentelemetry-api for Python < 3.12 to handle entry point loading differences when called with no arguments (SelectableGroups vs EntryPoints), avoiding DeprecationWarning and ensuring uniform behavior.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Existing tests pass

Does This PR Require a Contrib Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Comment thread uv.lock
Comment thread opentelemetry-api/src/opentelemetry/util/_importlib_metadata.py Outdated
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
@aabmass aabmass force-pushed the remove-importlib-metadata branch from a95351b to d81c1ba Compare May 13, 2026 19:44
- 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
Comment thread opentelemetry-api/src/opentelemetry/util/_importlib_metadata.py Outdated
@aabmass aabmass force-pushed the remove-importlib-metadata branch from d81c1ba to b4a11e4 Compare May 13, 2026 20:18
Co-authored-by: Lukas Hering <40302054+herin049@users.noreply.github.com>
@aabmass aabmass marked this pull request as ready for review May 13, 2026 20:51
@aabmass aabmass requested a review from a team as a code owner May 13, 2026 20:51
@aabmass aabmass force-pushed the remove-importlib-metadata branch from cdf7821 to 9fce4d5 Compare May 13, 2026 21:08
- 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
@aabmass
Copy link
Copy Markdown
Member Author

aabmass commented May 13, 2026

Would like an approval from another maintainer and then we can merge

Copy link
Copy Markdown
Member

@emdneto emdneto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@xrmx xrmx moved this from Approved PRs to Ready for merge in Python PR digest May 14, 2026
@xrmx xrmx enabled auto-merge (squash) May 14, 2026 15:24
@xrmx xrmx merged commit 1a33c69 into open-telemetry:main May 14, 2026
479 checks passed
@github-project-automation github-project-automation Bot moved this from Ready for merge to Done in Python PR digest May 14, 2026
@aabmass aabmass deleted the remove-importlib-metadata branch May 14, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

importlib-metadata breaks code

4 participants