Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make entry_points behave the same across Python versions #3167

Closed
ocelotl opened this issue Feb 8, 2023 · 4 comments · Fixed by #3217
Closed

Make entry_points behave the same across Python versions #3167

ocelotl opened this issue Feb 8, 2023 · 4 comments · Fixed by #3217
Assignees
Labels
bug Something isn't working

Comments

@ocelotl
Copy link
Contributor

ocelotl commented Feb 8, 2023

The recently introduced entry_points function does not behave the same across Python versions and it is not possible to get all entry points in Python 3.8 and 3.9.

@ocelotl ocelotl added the bug Something isn't working label Feb 8, 2023
@ocelotl ocelotl self-assigned this Feb 8, 2023
ocelotl added a commit to ocelotl/opentelemetry-python that referenced this issue Feb 8, 2023
@lzchen
Copy link
Contributor

lzchen commented Feb 8, 2023

@ocelotl

Do you have an example in which this does not work in 3.8 and 3.9 so we can try to reproduce?

@ocelotl
Copy link
Contributor Author

ocelotl commented Feb 23, 2023

@ocelotl

Do you have an example in which this does not work in 3.8 and 3.9 so we can try to reproduce?

Ok, so we have 2 issues:

  1. We may need to go through all the entry points in some scenario, the current implementation of our entry_points function requires both group and name which a user who wants all entry points won't know, that's why all the implementations of the functions that give entry points in importlib or importlib_metadata have both group or name or their equivalents as optional arguments.
  2. The replacements of pkg_resources functions that return entry points in importlib or importlib_metadata are very inconsistent across Python versions, for example 3.8 has an entry_points function that returns a dictionary, 3.10 returns a collection of entry point objects.

The idea behind this PR is to solve both issues by creating a private module that we can use in OTel components to access entry points that provides an uniform API and allows for selecting entry points by group, name or none of them.

ocelotl added a commit to ocelotl/opentelemetry-python that referenced this issue Feb 24, 2023
@aabmass
Copy link
Member

aabmass commented Mar 6, 2023

@ocelotl I have a high level question. Rather than add our own wrapper library, could we just use the importlib-metadata package instead regardless of version? Right now we have this conditional requirement

"importlib-metadata >= 5.0.0; python_version=='3.7'"

Once we drop Python 3.9 in the distant future, we could move to stdlib importlib.metadata. Are there any downsides to this?

ocelotl added a commit to ocelotl/opentelemetry-python that referenced this issue Mar 13, 2023
ocelotl added a commit to ocelotl/opentelemetry-python that referenced this issue Mar 13, 2023
ocelotl added a commit to ocelotl/opentelemetry-python that referenced this issue Mar 13, 2023
ocelotl added a commit to ocelotl/opentelemetry-python that referenced this issue Mar 14, 2023
ocelotl added a commit to ocelotl/opentelemetry-python that referenced this issue Mar 14, 2023
ocelotl added a commit to ocelotl/opentelemetry-python that referenced this issue Mar 15, 2023
ocelotl added a commit to ocelotl/opentelemetry-python that referenced this issue Mar 16, 2023
ocelotl added a commit that referenced this issue Mar 16, 2023
* Use importlib-metadata regardless of Python version

Fixes #3167

* Fix lint

* Add FIXME comment

* Constraint importlib-metadata versions
ocelotl added a commit to ocelotl/opentelemetry-python that referenced this issue Mar 17, 2023
@agronholm
Copy link

agronholm commented Mar 23, 2023

Was there a need to unconditionally use importlib-metadata, even on Python >= 3.10? This change broke my application framework (Asphalt) because it does isinstance(value, EntryPoint), checking against importlib.metadata.EntryPoint, but after importlib_metadata is imported, iterating entry points (even through the stdlib facilities) yields EntryPoint instances from that third party library, which are NOT compatible with the stdlib ones!

EDIT: I see that importlib.metadata.EntryPoint is not directly documented in the API docs.

ocelotl added a commit to ocelotl/opentelemetry-python that referenced this issue Mar 23, 2023
ocelotl added a commit to ocelotl/opentelemetry-python that referenced this issue Mar 29, 2023
ocelotl added a commit that referenced this issue Mar 31, 2023
* Make entry_points behave the same across Python versions

Fixes #3167

* Refactor function

* Fix mypy

* Incorporate resource detectors to auto instrumentation

This is an experimental feature.

Fixes #3172

* Rename environment variable

* Revert previous commits

* Refactor to use importlib-metadata library

* Use get_aggregate_resources

* Fix mypy

* Add CHANGELOG entry

* Fix typo in environment variable

* Add OTELResourceDetector by default

* Move to unreleased section

* Fix entry point name in the documentation

* Update opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py

Co-authored-by: Srikanth Chekuri <[email protected]>

---------

Co-authored-by: Srikanth Chekuri <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants