Skip to content

Replace usage of pkg_resources (setuptools) with importlib(._)resources? #2927

@jenshnielsen

Description

@jenshnielsen

Is your feature request related to a problem?

Importing opentelemetry is rather slow due to the import of pkg_resources in opentelemetry.context here

It is a known shortcoming of pkg_resources that at import time it will pass all installed packages which is potentially slow.
In my use case it adds ~0.7 s to the import time.

For this reason setuptools actively discourages the use of pkg_resources See here

Describe the solution you'd like

Replace the use of pkg_resources with importlib.metadata / importlib.resources which is part of the python standard library in newer versions of python and use their backports in importlib_metadata / importlib_resources as needed for older python versions.

In this particular use case pkg_resources is used to find entry points and that should be replaceable by doing

from importlib_metadata import entry_points
...
(entry_point,) = entry_points(group="opentelemetry_context", name=configured_context)
_RUNTIME_CONTEXT = entry_point.load()

Describe alternatives you've considered

  • Keep the current state. Using code that is slow and discouraged by its owners.

Additional context

This will also mean that opentelemetry can potentially drop the need for a runtime dependency on setuptools and when older python versions (<3.9) are dropped only use the std library for entry point selection.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions