OpenTelemetry Flask Integration

This library builds on the OpenTelemetry WSGI middleware to track web requests in Flask applications. In addition to opentelemetry-ext-wsgi, it supports flask-specific features such as:

  • The Flask endpoint name is used as the Span name.

  • The http.route Span attribute is set so that one can see which URL rule matched a request.

Usage

from opentelemetry.ext.flask import FlaskInstrumentor
FlaskInstrumentor().instrument()  # This needs to be executed before importing Flask
from flask import Flask

app = Flask(__name__)

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

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

API

class opentelemetry.ext.flask.FlaskInstrumentor[source]

Bases: opentelemetry.auto_instrumentation.instrumentor.BaseInstrumentor

A instrumentor for flask.Flask

See BaseInstrumentor