OpenTelemetry Python SDK

How to have Python applications using the OpenTelemetry Python SDK report data to Lumigo


The steps to make a Python application report tracing data to Lumigo are a mix of programmatic setup and environment-based configuration.

This documentation does not cover how to add instrumentation to your Python code, but pointers are provided in the "What's Next" section at the end of the page.

Initialize the OpenTelemetry Python SDK

Assuming the following exporter setup in your Python application using the upstream OpenTelemetry Python SDK:

from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor

# Resource can be required for some backends, e.g. Jaeger
# If resource wouldn't be set - traces wouldn't appears in Jaeger
resource = Resource(attributes={
    "": "service"

# Important: Consider to set up the right OpenTelemetry Resource Detectors for
# the computing platform your application runs on!
tracer = trace.get_tracer(__name__)

otlp_exporter = OTLPSpanExporter()

span_processor = BatchSpanProcessor(otlp_exporter)


# Once you set the environment variables OTEL_EXPORTER_OTLP_ENDPOINT and
# OTEL_EXPORTER_OTLP_HEADERS, you are good to go! Enjoy Lumigo!


Do not hard-code the Lumigo token in your application

Although the OTLPSpanExporter would allow you to pass the Authorization header as a literal, we strongly advise not to hard-code the Lumigo token in the code of your application. Consider using the OTEL_EXPORTER_OTLP_HEADERS environment variable, or at least passing the Lumigo token as its own environment variable, and interpolate the header string you pass to OTLPSpanExporter.

Configure the OpenTelemetry Python SDK

The OpenTelemetry OTLP Exporters package of the OpenTelemetry Python SDK can be connected to Lumigo using the following environment variables:

Environment variableValue
OTEL_EXPORTER_OTLP_HEADERSAuthorization=LumigoToken <token>

Replace <token> with your Lumigo token, which is available in Settings -> Tracing -> Manual tracing, see the Lumigo Tokens documentation.


Resource Attributes are very important!

When you instantiate the TracerProvider, you can pass it a Resource, which contains attributes that describe the your Python application and the platform on which it runs. See the Supported Semantic Conventions page for a list of endorsed Resource Detectors that will provide data useful for your experience of using Lumigo.