Skip to main content
Sumo Logic

Python OpenTelemetry auto-instrumentation

OpenTelemetry Python instrumentation gives the possibility to capture telemetry data from the python written code applications. The best way to start it is to incorporate OpenTelemetry-Python. See a list of the supported libraries.

How to instrument your app?

The best way to instrument Python applications is to use OpenTelemetry-Python automatic instrumentation. This approach is simple, easy, and does not require many code changes. Only a few Python packages have to be installed to successfully instrument the code of the application.

Installation of the packages listed below is required to start the instrumentation.

$ pip install opentelemetry-sdk
$ pip install opentelemetry-instrumentation

The next step is related to the installation of the instrumented packages used in the application. Manual installation of the instrumented packages - solution requires the user to find libraries used in the code and then installation of their instrumented counterparts (e.g. Flask -> opentelemetry-instrumentation-flask). It is recommended to install the packages manually.

$ pip install opentelemetry-instrumentation-flask

After successful installation of the instrumented packages it is important to install and configure a span exporter. The most commonly used exporters are OTLP, Jaeger, and Zipkin.

OTLP exporter configuration - recommended

# Exporter installation
$ pip install opentelemetry-exporter-otlp

A few things have to be configured:

  • SERVICE_NAME - insert there application service name
  • OTLP_ENDPOINT_NAME - hostname address supporting OTLP protocol
  • OTLP_ENDPOINT_PORT - port of the hostname supporting OTLP protocol (default port 55680)

from opentelemetry import trace
from opentelemetry.exporter.otlp.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor

resource = Resource(labels={

tracer = trace.get_tracer(__name__)


span_processor = BatchExportSpanProcessor(exporter)


# Your application code below


When everything is configured and the code is ready, it is very simple to run an instrumented application.

$ opentelemetry-instrument python3