Skip to content

Importing opentelemetry.context issues a warning in Python 3.10 and 3.11 #5231

@contrast-jproberts

Description

@contrast-jproberts

Describe your environment

OS: reproduced on MacOS and Ubuntu
Python version: cpython-3.10.20, cpython-3.11.15
SDK version: N/A, this is a bug in the API
API version: 1.42.0

What happened?

I have a test suite for a project that integrates with opentelemetry. This test suite treats warnings as errors, and when I upgraded opentelemetry-api from 1.41.1 to 1.42.0, the tests using opentelemetry errored out on Python 3.10 and Python 3.11. There isn't an issue with Python 3.12+.

Steps to Reproduce

The following command returns a non-zero exit code in v1.42.0:

uv run --isolated -p 3.11 --with opentelemetry-api==1.42.0 python -W error -c 'import opentelemetry.context'

Expected Result

I expected the command to exit with 0, the same result as running v1.41.1 e.g.

uv run --isolated -p 3.11 --with opentelemetry-api==1.41.1 python -W error -c 'import opentelemetry.context'

Actual Result

> uv run --isolated -p 3.11 --with opentelemetry-api==1.42.0 python -W error -c 'import opentelemetry.context'
Failed to load context: contextvars_context, fallback to contextvars_context
Traceback (most recent call last):
  File "/Users/jamesroberts/.cache/uv/archive-v0/Te1o9iQKYZLDOiqN/lib/python3.11/site-packages/opentelemetry/context/__init__.py", line 36, in _load_runtime_context
    entry_points(  # type: ignore
  File "/Users/jamesroberts/.cache/uv/archive-v0/Te1o9iQKYZLDOiqN/lib/python3.11/site-packages/opentelemetry/util/_importlib_metadata.py", line 41, in entry_points
    return _original_entry_points_cached().select(**params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jamesroberts/.cache/uv/archive-v0/Te1o9iQKYZLDOiqN/lib/python3.11/site-packages/opentelemetry/util/_importlib_metadata.py", line 37, in _original_entry_points_cached
    return _as_entry_points(original_entry_points())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jamesroberts/.cache/uv/archive-v0/Te1o9iQKYZLDOiqN/lib/python3.11/site-packages/opentelemetry/util/_importlib_metadata.py", line 32, in _as_entry_points
    return EntryPoints(ep for group_eps in eps.values() for ep in group_eps)
                                           ^^^^^^^^^^^^
  File "/Users/jamesroberts/.local/share/uv/python/cpython-3.11.15-macos-aarch64-none/lib/python3.11/importlib/metadata/__init__.py", line 463, in values
    self._warn()
DeprecationWarning: SelectableGroups dict interface is deprecated. Use select.
Traceback (most recent call last):
  File "/Users/jamesroberts/.cache/uv/archive-v0/Te1o9iQKYZLDOiqN/lib/python3.11/site-packages/opentelemetry/context/__init__.py", line 36, in _load_runtime_context
    entry_points(  # type: ignore
  File "/Users/jamesroberts/.cache/uv/archive-v0/Te1o9iQKYZLDOiqN/lib/python3.11/site-packages/opentelemetry/util/_importlib_metadata.py", line 41, in entry_points
    return _original_entry_points_cached().select(**params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jamesroberts/.cache/uv/archive-v0/Te1o9iQKYZLDOiqN/lib/python3.11/site-packages/opentelemetry/util/_importlib_metadata.py", line 37, in _original_entry_points_cached
    return _as_entry_points(original_entry_points())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jamesroberts/.cache/uv/archive-v0/Te1o9iQKYZLDOiqN/lib/python3.11/site-packages/opentelemetry/util/_importlib_metadata.py", line 32, in _as_entry_points
    return EntryPoints(ep for group_eps in eps.values() for ep in group_eps)
                                           ^^^^^^^^^^^^
  File "/Users/jamesroberts/.local/share/uv/python/cpython-3.11.15-macos-aarch64-none/lib/python3.11/importlib/metadata/__init__.py", line 463, in values
    self._warn()
DeprecationWarning: SelectableGroups dict interface is deprecated. Use select.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/jamesroberts/.cache/uv/archive-v0/Te1o9iQKYZLDOiqN/lib/python3.11/site-packages/opentelemetry/context/__init__.py", line 58, in <module>
    _RUNTIME_CONTEXT = _load_runtime_context()
                       ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jamesroberts/.cache/uv/archive-v0/Te1o9iQKYZLDOiqN/lib/python3.11/site-packages/opentelemetry/context/__init__.py", line 50, in _load_runtime_context
    entry_points(  # type: ignore
  File "/Users/jamesroberts/.cache/uv/archive-v0/Te1o9iQKYZLDOiqN/lib/python3.11/site-packages/opentelemetry/util/_importlib_metadata.py", line 41, in entry_points
    return _original_entry_points_cached().select(**params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jamesroberts/.cache/uv/archive-v0/Te1o9iQKYZLDOiqN/lib/python3.11/site-packages/opentelemetry/util/_importlib_metadata.py", line 37, in _original_entry_points_cached
    return _as_entry_points(original_entry_points())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jamesroberts/.cache/uv/archive-v0/Te1o9iQKYZLDOiqN/lib/python3.11/site-packages/opentelemetry/util/_importlib_metadata.py", line 32, in _as_entry_points
    return EntryPoints(ep for group_eps in eps.values() for ep in group_eps)
                                           ^^^^^^^^^^^^
  File "/Users/jamesroberts/.local/share/uv/python/cpython-3.11.15-macos-aarch64-none/lib/python3.11/importlib/metadata/__init__.py", line 463, in values
    self._warn()
DeprecationWarning: SelectableGroups dict interface is deprecated. Use select.

Additional context

I believe this is the commit that introduced the new behavior: 1a33c69

Would you like to implement a fix?

None

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions