open-telemetry / opentelemetry-python-contrib

OpenTelemetry instrumentation for Python modules
https://opentelemetry.io
Apache License 2.0
733 stars 604 forks source link

DeprecationWarning: Inheritance class _InstrumentedApplication from web.Application is discouraged in aiohttp-server instrumentation #2859

Open phillipuniverse opened 1 month ago

phillipuniverse commented 1 month ago

Describe your environment

OS: MacOS Python version: Python 3.11.8 Package version: 0.48b0

What happened?

Getting a deprecation warning when activating aiohttp-server instrumentation target aiohttp 3.9.3:

DeprecationWarning: Inheritance class _InstrumentedApplication from web.Application is discouraged

Steps to Reproduce

Use auto-instrumentation for the aiohttp library after including opentelemetry-instrumentation-aiohttp.

Expected Result

No deprecation warning

Actual Result

Following stack trace (with warnings turned into errors from Pytest):

Traceback (most recent call last):
  File "/Users/phillip/Library/Caches/pypoetry/virtualenvs/shipwell-common-python-zjZyLK7l-py3.11/lib/python3.11/site-packages/opentelemetry/instrumentation/auto_instrumentation/_load.py", line 87, in _load_instrumentors
    distro.load_instrumentor(entry_point, skip_dep_check=True)
  File "/Users/phillip/Library/Caches/pypoetry/virtualenvs/shipwell-common-python-zjZyLK7l-py3.11/lib/python3.11/site-packages/opentelemetry/instrumentation/distro.py", line 63, in load_instrumentor
    instrumentor: BaseInstrumentor = entry_point.load()
                                     ^^^^^^^^^^^^^^^^^^
  File "/Users/phillip/Library/Caches/pypoetry/virtualenvs/shipwell-common-python-zjZyLK7l-py3.11/lib/python3.11/site-packages/pkg_resources/__init__.py", line 2496, in load
    return self.resolve()
           ^^^^^^^^^^^^^^
  File "/Users/phillip/Library/Caches/pypoetry/virtualenvs/shipwell-common-python-zjZyLK7l-py3.11/lib/python3.11/site-packages/pkg_resources/__init__.py", line 2502, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/phillip/Library/Caches/pypoetry/virtualenvs/shipwell-common-python-zjZyLK7l-py3.11/lib/python3.11/site-packages/opentelemetry/instrumentation/aiohttp_server/__init__.py", line 242, in <module>
    class _InstrumentedApplication(web.Application):
  File "<frozen abc>", line 106, in __new__
  File "/Users/phillip/Library/Caches/pypoetry/virtualenvs/shipwell-common-python-zjZyLK7l-py3.11/lib/python3.11/site-packages/aiohttp/web_app.py", line 161, in __init_subclass__
    warnings.warn(
DeprecationWarning: Inheritance class _InstrumentedApplication from web.Application is discouraged

Additional context

It appears this ends up breaking all http instrumentation, should this be a bit of a softer error and only break this specific instrumentation? Meaning this re-raise:

https://github.com/open-telemetry/opentelemetry-python-contrib/blob/6f1a17d8dd5d2f2f51cfe9d65e57cc8d16632154/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/_load.py#L89-L91

Would you like to implement a fix?

None

xrmx commented 1 month ago

Are you reporting that tests don't work if you turn warnings to errors?

phillipuniverse commented 1 month ago

I'm kind of reporting 2 things:

  1. The aiohttp-server instrumentation emits a DeprecationWarning on aiohttp-3.9.3 (maybe other versions too)
  2. In my particular case, I have warnings turned into errors so a real exception is thrown. However, it highlights the case where instrumentation could fail with an exception (like maybe patching something that doesn't exist) and the exception prevents any other instrumentation from running because of the re-raise in the code I linked