Skip to content

New DeprecationWarning with opentelemetry-test-utils #4836

@phillipuniverse

Description

@phillipuniverse

Describe your environment

OS: MacOS
Python version: 3.10
SDK version: 1.39.0
API version: 1.39.0

What happened?

I'm using the opentelemetry test utils and after #4654, I get a new DeprecationWarning because the tests import the events api:

Which gives this new warning:

.venv/lib/python3.10/site-packages/_pytest/assertion/rewrite.py:186: in exec_module
    exec(co, module.__dict__)
.venv/lib/python3.10/site-packages/opentelemetry/test/test_base.py:38: in <module>
    from opentelemetry.test.globals_test import (
<frozen importlib._bootstrap>:1027: in _find_and_load
    ???
<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:688: in _load_unlocked
    ???
.venv/lib/python3.10/site-packages/_pytest/assertion/rewrite.py:186: in exec_module
    exec(co, module.__dict__)
.venv/lib/python3.10/site-packages/opentelemetry/test/globals_test.py:17: in <module>
    from opentelemetry import _events as events_api
.venv/lib/python3.10/site-packages/opentelemetry/_events/__init__.py:94: in <module>
    class NoOpEventLogger(EventLogger):
../../.local/share/uv/python/cpython-3.10.19-macos-aarch64-none/lib/python3.10/abc.py:106: in __new__
    cls = super().__new__(mcls, name, bases, namespace, **kwargs)
.venv/lib/python3.10/site-packages/typing_extensions.py:2988: in __init_subclass__
    warnings.warn(msg, category=category, stacklevel=stacklevel + 1)
E   DeprecationWarning: You should use `Logger` instead. Deprecated since version 1.39.0 and will be removed in a future release.

This will get fixed when the events API is removed, maybe in the meantime we can move the import of the events_api inside of reset_event_globals() to avoid the warning on import?

def reset_event_globals() -> None:
"""WARNING: only use this for tests."""
events_api._EVENT_LOGGER_PROVIDER_SET_ONCE = Once() # type: ignore[attr-defined]
events_api._EVENT_LOGGER_PROVIDER = None # type: ignore[attr-defined]
events_api._PROXY_EVENT_LOGGER_PROVIDER = (
events_api.ProxyEventLoggerProvider()
) # type: ignore[attr-defined]

Steps to Reproduce

To trigger, simply import TestBase:

from opentelemetry.test.test_base import TestBase

Expected Result

No warning

Actual Result

Got a warning

Additional context

No response

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions