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

Improper status code handling between flask and wsgi instrumentation: bare status codes.

Open
#575 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Flask's Response type status field can be just a simple string or an integer but the wsgi instrumentation here expects it to be able to be split on a string (understandable as that's wsgi / pep 3333 compliant).

This line https://github.com/open-telemetry/opentelemetry-python-contrib/blob/753e22896a11cadf28c4f64acdfcfd73350d7d90/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py#L107-L110

Can blow up in this manner:

  File "/usr/local/lib/python/dist-packages/flask/app.py", line 2453, in wsgi_app
    return response(environ, start_response)
  File "/usr/local/lib/python/dist-packages/werkzeug/wrappers/base_response.py", line 701, in __call__
    start_response(status, headers)
  File "/usr/local/lib/python/dist-packages/opentelemetry/instrumentation/flask/__init__.py", line 109, in _start_response
    span, status, response_headers
  File "/usr/local/lib/python/dist-packages/opentelemetry/instrumentation/wsgi/__init__.py", line 163, in add_response_attributes
    status_code, _ = start_response_status.split(" ", 1)
ValueError: not enough values to unpack (expected 2, got 1)

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

Read instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/init.py around lines 107-110 and the WSGI add_response_attributes entry point. Reproduce the failure with a Flask response using a bare status string or integer, then verify instrumentation handles it without the split error while preserving response status attributes.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.