opentelemetry-python-contrib
opentelemetry-python-contrib copied to clipboard
Flask Instrumentation doesn't work with "from flask import Flask"
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)