OpenTelemetry Flask Instrumentation

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

  • The Flask url rule pattern is used as the Span name.

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


from flask import Flask
from opentelemetry.instrumentation.flask import FlaskInstrumentor

app = Flask(__name__)


def hello():
    return "Hello!"

if __name__ == "__main__":


class opentelemetry.instrumentation.flask.FlaskInstrumentor(*args, **kwargs)[source]

Bases: opentelemetry.instrumentation.instrumentor.BaseInstrumentor

An instrumentor for flask.Flask

See BaseInstrumentor


Return a list of python packages with versions that the will be instrumented.

The format should be the same as used in requirements.txt or

For example, if an instrumentation instruments requests 1.x, this method should look like:

def instrumentation_dependencies(self) -> Collection[str]:

return [‘requests ~= 1.0’]

This will ensure that the instrumentation will only be used when the specified library is present in the environment.

Return type


static instrument_app(app, request_hook=None, response_hook=None, tracer_provider=None, excluded_urls=None)[source]
static uninstrument_app(app)[source]