open-telemetry / open-telemetry/opentelemetry-python-contrib
Flask Instrumentation doesn't work with "from flask import Flask"
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
Steps to reproduce
Flask does not work with "from flask import Flask":
from flask import Flask
from opentelemetry.instrumentation.flask import FlaskInstrumentor
FlaskInstrumentor().instrument()
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello!"
if __name__ == "__main__":
app.run(debug=True)
What is the expected behavior?
Flask calls should be instrumented
What is the actual behavior?
Flask calls are not instrumentated
Additional context
The instrumentation only works if the imports are set up as such:
import flask
from opentelemetry.instrumentation.flask import FlaskInstrumentor
FlaskInstrumentor().instrument()
app = flast.Flask(__name__)
@app.route("/")
def hello():
return "Hello!"
if __name__ == "__main__":
app.run(debug=True)
It also works if you use the instrument_app method instead:
from flask import Flask
from opentelemetry.instrumentation.flask import FlaskInstrumentor
app = Flask(__name__)
FlaskInstrumentor().instrument_app(app)
@app.route("/")
def hello():
return "Hello!"
if __name__ == "__main__":
app.run(debug=True)
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 with FlaskInstrumentor().instrument() and compare its behavior with instrument_app(app) in the reproduction examples. Trace how the Flask class is discovered when imported directly versus through the flask module, then add coverage for both import styles and verify that Flask calls are instrumented without requiring instrument_app.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, python
- Domain
- backend, observability
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100