Skip to content

Flask

The logfire.instrument_flask() method will create a span for every request to your Flask application.

Install

Install logfire with the flask extra:

pip install 'logfire[flask]'
rye add logfire -E flask
poetry add 'logfire[flask]'
uv add 'logfire[flask]'

Usage

Let's see a minimal example below. You can run it with python main.py:

main.py
import logfire
from flask import Flask


logfire.configure()

app = Flask(__name__)
logfire.instrument_flask(app)


@app.route("/")
def hello():
    return "Hello!"


if __name__ == "__main__":
    app.run(debug=True)

The keyword arguments of logfire.instrument_flask() are passed to the FlaskInstrumentor().instrument_app() method of the OpenTelemetry Flask Instrumentation package, read more about it here.

Capturing request and response headers