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

Flask Instrumentation doesn't work with "from flask import Flask"

Open
#1,921 9 comments 2 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

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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.