OpenTelemetry Python: Getting Started with Auto and Manual Instrumentation

By the OpenTelemetry.app editorial team 4 min readUpdated November 16, 2026
Illustrated cover for the guide: OpenTelemetry Python: Getting Started with Auto and Manual Instrumentation

OpenTelemetry Python is the official API and SDK for Python applications. According to the official status table, Python traces and metrics are Stable while logs are still in Development. This guide gets you from zero to exported traces quickly.

Key takeaways

  • pip install opentelemetry-distro plus an exporter, then run opentelemetry-bootstrap.
  • opentelemetry-instrument gives zero-code traces for popular libraries.
  • Python traces and metrics are Stable; logs are in Development.
  • Add manual spans for business context.

Install the packages

python -m venv .venv
source .venv/bin/activate      # Windows: .venv\Scripts\activate
pip install opentelemetry-distro opentelemetry-exporter-otlp
opentelemetry-bootstrap -a install

opentelemetry-distro brings the API, SDK and the opentelemetry-instrument command. opentelemetry-bootstrap inspects your installed libraries (Flask, Django, requests, SQLAlchemy and more) and installs matching instrumentation packages. Check PyPI for the Python versions each release supports.

Zero-code instrumentation

export OTEL_SERVICE_NAME=orders-api
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
opentelemetry-instrument python app.py

The wrapper initialises the SDK and instruments supported libraries automatically. To see output without a backend, use --traces_exporter console.

Adding manual spans

from opentelemetry import trace

tracer = trace.get_tracer("orders")

def place_order(order):
    with tracer.start_as_current_span("place_order") as span:
        span.set_attribute("order.items", len(order.items))
        charge(order)

Manual spans nest under auto-instrumented ones, adding business context to traces.

Recording a metric

from opentelemetry import metrics

meter = metrics.get_meter("orders")
orders_counter = meter.create_counter("orders.placed")
orders_counter.add(1, {"payment.method": "card"})

Signal status in Python

Status from the official opentelemetry.io language table, checked November 16, 2026.
SignalPython status
TracesStable
MetricsStable
LogsDevelopment

Example: a Flask app

pip install flask
opentelemetry-bootstrap -a install   # adds Flask instrumentation
export OTEL_SERVICE_NAME=shop
opentelemetry-instrument --traces_exporter console flask run

Every request to the app now prints a span with the route, method and status code. Swap console for otlp and set the endpoint to send it to a Collector instead.

Troubleshooting Python instrumentation

  • No spans appear: run with the console exporter to check the SDK is active; confirm the library is supported and its instrumentation package is installed.
  • Version conflicts: instrumentation packages are versioned to match the SDK — upgrade them together.
  • Duplicate spans: avoid combining auto-instrumentation with manual instrumentation of the same library.

Tips for production

  • Pin package versions together — API, SDK and instrumentation packages are released in coordinated sets.
  • With pre-fork servers such as Gunicorn, follow the documented guidance for initialising the SDK in each worker.
  • Send data to a local Collector rather than directly to a vendor.
  • Set OTEL_SERVICE_NAME for every service.

Frequently asked questions

Does OpenTelemetry Python work with Django and Flask?

Yes. Instrumentation packages exist for both and are installed by opentelemetry-bootstrap when the framework is present.

Can I use OpenTelemetry Python on Windows?

Yes. It is pure Python packaging; only the virtual-environment activation command differs.

How do I see traces without a backend?

Use the console exporter, for example opentelemetry-instrument --traces_exporter console python app.py.

Get OpenTelemetry from the official source

Free and open source (Apache 2.0) — the Go source .zip downloads straight from GitHub.

Download OpenTelemetry

Downloads the OpenTelemetry Go source code (.zip, main branch) from the official GitHub repository — you stay on this page.