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:

{{ install_logfire(extras=['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


本文总阅读量次