Skip to content

Instrumentations for Python

Instrumentations are plugins for popular frameworks and libraries which use OpenTelemetry API to record important operations such as HTTP requests, DB queries, logs, errors, and more.

See opentelemetry-python for the full list of available instrumentations.

Framework

HTTP

Database

Logging

Other

Auto-instrumentation

Note

When possible you should prefer explicit instrumentation. For example, auto-instrumentation does not work with Flask in debug mode.

opentelemetry-python allows you to automatically instrument app using opentelemetry-instrument utility from opentelemetry-instrumentation package.

First you need to install opentelemetry-instrument executable:

pip install opentelemetry-instrumentation

Then install instrumentations that should be applied automatically by opentelemetry-instrument:

pip install opentelemetry-instrumentation-flask

And run you app using opentelemetry-instrument wrapper:

UPTRACE_DSN="https://<token>@api.uptrace.dev/<project_id>" opentelemetry-instrument python3 main.py

See flask-auto-instrumentation example for full details.

How auto-instrumentation works?

uptrace-python registers an OpenTelemetry distro using an entry point in setup.cfg. Instrumentations register themselves using the same mechanism. OpenTelemetry then just calls the code specified in entry points to configure OpenTelemetry SDK and instrument the code.