open-telemetry / open-telemetry/opentelemetry-python-contrib
AttributeError in opentelemetry-instrumentation-aiohttp-server
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 1.1k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 16
Description
Describe your environment
OS: Ubuntu 22.04
Python version: 3.10.12
Package version: 0.47b0
What happened?
I have a web app written with aiohttp and followed the installation instructions of the opentelemetry SDK.
I did not see the app misbehave, but I noticed an exception that
- was printed to STDOUT and
- was sent to the otel collector
Steps to Reproduce
- I started SigNoz locally (with the default docker-compose file).
- I started with an already existing web app based on aiohttp.
- I installed the OTEL SDK and ran opentelemetry-bootstrap.
- I defined some env. vars and ran the server.
$ cat .env2
OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED="true"
OTEL_SERVICE_NAME="demo"
OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318"
OTEL_PYTHON_LOG_CORRELATION="true"
OTEL_PYTHON_LOG_LEVEL="debug"
OTEL_METRICS_EXPORTER="otlp"
OTEL_METRIC_INTERVAL=5000
$ . .env2
$ opentelemetry-instrument --service_name demo gunicorn demo:app --bind 0.0.0.0:8080 --worker-class aiohttp.GunicornWebWorker
Unfortunately, I'm uncertain about the steps until noticing the traceback, but SigNoz suggests that the traceback was printed from a trace/span that was handling a websocket connection.
Expected Result
I would expect to see no traceback
Actual Result
Traceback on STDOUT
[2024-10-11 15:07:40 +0200] [86402] [ERROR] Error handling request
Traceback (most recent call last):
File "/home/andi/virtualenvs/checkers/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 477, in _handle_request
resp = await request_handler(request)
File "/home/andi/virtualenvs/checkers/lib/python3.10/site-packages/aiohttp/web_app.py", line 559, in _handle
return await handler(request)
File "/home/andi/virtualenvs/checkers/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
return await handler(request)
File "/home/andi/virtualenvs/checkers/lib/python3.10/site-packages/opentelemetry/instrumentation/aiohttp_server/__init__.py", line 231, in middleware
set_status_code(span, resp.status)
AttributeError: 'NoneType' object has no attribute 'status'
Traceback in SigNoz
Traceback (most recent call last):
File "/home/andi/virtualenvs/checkers/lib/python3.10/site-packages/opentelemetry/trace/__init__.py", line 583, in use_span
yield span
File "/home/andi/virtualenvs/checkers/lib/python3.10/site-packages/opentelemetry/sdk/trace/__init__.py", line 1108, in start_as_current_span
yield span
File "/home/andi/virtualenvs/checkers/lib/python3.10/site-packages/opentelemetry/instrumentation/aiohttp_server/__init__.py", line 231, in middleware
set_status_code(span, resp.status)
AttributeError: 'NoneType' object has no attribute 'status'
Additional context
No response
Would you like to implement a fix?
None
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in opentelemetry/instrumentation/aiohttp_server/init.py at the middleware around line 231, then reproduce the reported aiohttp setup with the websocket scenario described. Done means the request completes without the NoneType traceback being printed or sent to the collector.
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