open-telemetry / open-telemetry/opentelemetry-python-contrib

aiohttp-server instrumentation doesn't work with several types of importing

Open
#3,221 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
1.1k
Forks
1.1k
Avg merge
4d 15h
Merged PRs (30d)
16

Description

Describe your environment

Problem not related to the environment

What happened?

Instrumentation doesn't work with several types of importing. Problem with injecting technique through setattr. Looks like it not the best solution because not works with some imports variants.

Steps to Reproduce
from aiohttp import web
from aiohttp.web import Application
from aiohttp.web_app import Application as ApplicationFromWebApp
from aiohttp import web_app

print(web.Application)
print(Application)
print(web_app.Application)
print(ApplicationFromWebApp)


from opentelemetry.instrumentation.aiohttp_server import AioHttpServerInstrumentor

AioHttpServerInstrumentor().instrument()

print("instrumentation enable")

print(web.Application)
print(Application)
print(web_app.Application)
print(ApplicationFromWebApp)

Expected Result
<class 'aiohttp.web_app.Application'>
<class 'aiohttp.web_app.Application'>
<class 'aiohttp.web_app.Application'>
<class 'aiohttp.web_app.Application'>
instrumentation enable
<class 'opentelemetry.instrumentation.aiohttp_server._InstrumentedApplication'>
<class 'opentelemetry.instrumentation.aiohttp_server._InstrumentedApplication'>
<class 'opentelemetry.instrumentation.aiohttp_server._InstrumentedApplication'>
<class 'opentelemetry.instrumentation.aiohttp_server._InstrumentedApplication'>
Actual Result
<class 'aiohttp.web_app.Application'>
<class 'aiohttp.web_app.Application'>
<class 'aiohttp.web_app.Application'>
<class 'aiohttp.web_app.Application'>
instrumentation enable
<class 'opentelemetry.instrumentation.aiohttp_server._InstrumentedApplication'>
<class 'aiohttp.web_app.Application'>
<class 'aiohttp.web_app.Application'>
<class 'aiohttp.web_app.Application'>
Additional context

No response

Would you like to implement a fix?

yes

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in instrumentation/opentelemetry-instrumentation-aiohttp-server/src/opentelemetry/instrumentation/aiohttp_server/init.py around the setattr call linked in the issue, then reproduce the listed import variants. Done means each alias resolves to the instrumented Application class after AioHttpServerInstrumentor().instrument().

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.