OpenTelemetry Flask Instrumentation

This library builds on the OpenTelemetry WSGI middleware to track web requests in Flask applications. In addition to opentelemetry-instrumentation-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 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)

API

opentelemetry.instrumentation.flask.get_excluded_urls()[source]
class opentelemetry.instrumentation.flask.FlaskInstrumentor[source]

Bases: opentelemetry.instrumentation.instrumentor.BaseInstrumentor

An instrumentor for flask.Flask

See BaseInstrumentor

instrument_app(app)[source]
uninstrument_app(app)[source]