To set up OpenTelemetry in a Python backend, install opentelemetry-distro and opentelemetry-exporter-otlp, run opentelemetry-bootstrap -a install, set four environment variables, and start the app with opentelemetry-instrument. FastAPI, Django and Flask then send traces, metrics and their standard logs, errors with stack traces included, with no code change.1,3
That is the whole setup, and it is the same for all three frameworks. The parts that go wrong are around it: the exporter defaults to gRPC, logs only arrive from Python's logging module, and several workers quietly drop metrics. This post covers the setup step by step, then those traps, then what the data turns into once it lands. If you would rather not do it by hand, your coding agent can: paste "Read fixter.dev/llms.txt and set up Fixter." into Claude Code or Cursor in your project.13
What you get for each framework
OpenTelemetry's Python agent patches libraries when your process starts, so you do not add tracing calls to your handlers.1 opentelemetry-bootstrap looks at the packages you have installed and adds the matching instrumentation for each one.1,5
| FastAPI | Django | Flask | |
|---|---|---|---|
| Instrumentation package | opentelemetry-instrumentation-fastapi | opentelemetry-instrumentation-django | opentelemetry-instrumentation-flask |
| Start command | opentelemetry-instrument uvicorn main:app | opentelemetry-instrument python manage.py runserver --noreload | opentelemetry-instrument flask run -p 8080 |
| A span for each request | Yes | Yes | Yes |
| Database and outbound calls | Yes, for installed libraries such as SQLAlchemy, asyncpg, Redis and httpx | Yes, for installed libraries such as psycopg, Redis, Celery and requests | Yes, for installed libraries such as SQLAlchemy, psycopg, Redis and requests |
| Logs from the logging module | Yes | Yes | Yes |
| Trap in development | None listed in the OpenTelemetry docs | Set DJANGO_SETTINGS_MODULE in the environment, and the auto-reloader runs the app twice: use --noreload | Debug mode turns on a reloader that breaks instrumentation: set use_reloader=False |
| Several workers in production | Gunicorn with UvicornWorker keeps metrics | Plain Gunicorn workers lose metrics unless you use a post_fork hook | Plain Gunicorn workers lose metrics unless you use a post_fork hook |
From the OpenTelemetry Python docs and the opentelemetry-python-contrib repository at v0.66b2, November 13, 2026.4,5,9,10
The current release is opentelemetry-sdk 1.45.2, published October 29, 2026. It needs Python 3.10 or newer.8
How to set up OpenTelemetry in Python, in five steps
The steps below send to Fixter. The first and fourth are the same for any backend that accepts OTLP, and the variables in step three are standard OpenTelemetry with Fixter's endpoint and key in them.2,11
- Install the packages. Run this in the same virtual environment as your app, after your own dependencies are installed, because
opentelemetry-bootstrapreads what is there.1
With uv, the OpenTelemetry docs warn that opentelemetry-bootstrap -a install can leave dependencies in a bad state. Use this instead, and run it again after each uv sync:4
- Create an API key. In the Fixter app, open Settings, API keys and create one. It starts with
fixter_sk_and is shown once, so store it with your other secrets asFIXTER_API_KEY.11 - Set four environment variables, wherever your deploy defines its environment: the shell, a compose file, the Deployment's
envblock.11
The protocol line matters in Python. The default distro sets the OTLP protocol to gRPC, and Fixter takes OTLP over HTTP, so without http/protobuf the exporter fails.6,11 The same distro already sets the traces, metrics and logs exporters to otlp, so you do not set those yourself.6 The fifth line names the environment; it is one extra line and keeps production apart from staging later.11
Django needs one more variable. Set DJANGO_SETTINGS_MODULE in the environment, as the OpenTelemetry Django example does, and not only in manage.py.9 The Django instrumentation reads it when the process starts, and without it falls back to empty Django settings.14
- Check that it arrived. Send a request to your app, then open the Logs page in Fixter and filter on your service name. Or ask your coding agent, once it is connected to Fixter over MCP: "Show me the last errors from checkout-service."11
Health checks fill traces with noise. To leave them out, set OTEL_PYTHON_EXCLUDED_URLS to a comma-separated list of regular expressions, for example healthcheck.2
Logs and errors: what arrives
Traces come from the framework instrumentation. Logs come from a bridge on Python's standard logging module, the package opentelemetry-instrumentation-logging. opentelemetry-bootstrap installs it by default, and since OpenTelemetry Python 1.40.0 it is switched on by default too.3,5 On an older version, set OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true.3
Three things follow from how the bridge works:
- Use the logging module. The bridge is a handler on
logging. Output written withprintnever passes through it, so it is not exported.7 - Log the exception, not just a message. A record logged with exception info, which is what
logger.exceptiondoes, is exported withexception.type,exception.messageandexception.stacktrace.7 That stack trace is what lets a monitoring tool group the same error into one issue. - Each log carries its trace. A record written during a request is exported with that request's trace context, so you can go from an error line to the request that produced it.7
Two variables are worth knowing. OTEL_PYTHON_LOG_CORRELATION=true adds the trace id to the lines your app prints to the console as well, and OTEL_PYTHON_LOG_AUTO_INSTRUMENTATION=false turns the log bridge off if you ship logs another way.2
Gunicorn and Uvicorn workers
This is the trap that shows up only in production. A server that forks worker processes copies the OpenTelemetry setup into each child, but not the background thread that exports metrics. The OpenTelemetry docs list what still arrives with several workers:4
| Server with several workers | Traces | Metrics | Logs |
|---|---|---|---|
| Uvicorn | Yes | No | Yes |
| Gunicorn | Yes | No | Yes |
| Gunicorn with UvicornWorker | Yes | Yes | Yes |
Traces and logs survive in every row, so errors still reach you. If you want metrics too, there are two fixes from the same docs page.4 For a FastAPI or other ASGI app, run Gunicorn with the Uvicorn worker class:
For Django or Flask on plain Gunicorn, start OpenTelemetry inside each worker after the fork, and drop opentelemetry-instrument from the command:
With plain uvicorn main:app --workers 2, call initialize() at the top of your app module instead, before the line that imports FastAPI.4
What shows up as issues
Telemetry on its own is a pile of rows. What you want from it is a short list of what is broken. Fixter (fixter.dev) finds and fixes the issues in your app in production, from your coding agent: errors, failing infrastructure, slow requests and downtime. It finds the root cause and fixes it: in your agent over MCP, or as a pull request ready for your review. Nothing to learn, built for small teams.
With the setup above, this is what your Python app's data becomes:12
- One issue for each error, not one row for each time it happened. Fixter parses the Python stack trace and groups every occurrence with the same cause, so a
KeyErrorthrown thousands of times is one issue with a count. Errors that differ only by an id, such as "Order 8f2c1a not found" and "Order b31e07 not found", stay together. - Error logs with no exception. An ERROR line with no stack trace is grouped by its message.
- Where to look. Each issue names the exception type and message, the frame that threw and the frame that called it, the service, when it was first and last seen, and a link to the trace and log of each occurrence.
- Staging and production kept apart. The environment name from step three is recorded on every occurrence.
There is no separate error SDK to add for this. The issues are built from the logs and traces you already send.12 You hear about a new one by email or Slack, and you can ask about them from your coding agent. For the agent side, see how to debug production with Claude Code and how to set up error monitoring with Claude Code. If your app also calls a model, Claude API tracing puts those calls in the same traces.
If nothing shows up
- Exporter errors that mention gRPC. Set
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf.6,11 - A 401 in the exporter output. The
Authorizationheader is not reaching Fixter or the key was revoked. Check that the variable is set in the process's own environment, not only in your shell.11 - No spans from a framework. Its instrumentation package is missing. Run
opentelemetry-bootstrapwith no arguments to list what it recommends for your environment, and run it again after you add a library.1 - Nothing in development. A reloader is running your app in a second process. Use
--noreloadwith Django's runserver anduse_reloader=Falsewith Flask's debug mode.4,9 - Traces but no logs. The app writes with
print, or runs an OpenTelemetry Python older than 1.40.0 without the variable that turns the log bridge on.3 - Traces and logs but no metrics. Several workers. See the section above.4
- Data under the wrong name. Set
OTEL_SERVICE_NAME.11
Key takeaways
- Two pip packages, opentelemetry-bootstrap -a install, four environment variables, then opentelemetry-instrument in front of your start command
- The same setup covers FastAPI, Django and Flask, with no code change
- Python's distro defaults to gRPC: set the protocol to http/protobuf for a backend that takes OTLP over HTTP
- Logs arrive from the logging module, on by default since OpenTelemetry Python 1.40.0; print output does not
- Several Gunicorn or Uvicorn workers drop metrics, not traces or logs
- Or paste "Read fixter.dev/llms.txt and set up Fixter." into your coding agent
Frequently asked questions
How do I add OpenTelemetry to a Python app without changing code?
Install opentelemetry-distro and opentelemetry-exporter-otlp with pip, run opentelemetry-bootstrap -a install, set the OTEL_ environment variables for your backend, and start the app with opentelemetry-instrument in front of your usual command. The agent patches FastAPI, Django, Flask, database drivers and HTTP clients when the process starts.
Does OpenTelemetry auto-instrumentation work with FastAPI, Django and Flask?
Yes. opentelemetry-bootstrap reads your installed packages and adds the matching instrumentation: opentelemetry-instrumentation-fastapi, -django or -flask, plus the ones for libraries such as SQLAlchemy, psycopg, Redis, Celery, requests and httpx. You start each framework with opentelemetry-instrument in front of its normal command.
Does OpenTelemetry Python export logs automatically?
Yes, for Python's standard logging module. opentelemetry-bootstrap installs opentelemetry-instrumentation-logging, and since OpenTelemetry Python 1.40.0 it is on by default. On older versions set OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true. Output written with print is not exported.
Why does my Python app send traces but no metrics with Gunicorn or Uvicorn workers?
Forking breaks the background thread that exports metrics. With several workers, plain Uvicorn and plain Gunicorn still send traces and logs but not metrics. Gunicorn with the UvicornWorker class sends all three. For other setups, start OpenTelemetry inside each worker, for example in a Gunicorn post_fork hook.
Why do I get gRPC errors when exporting from Python?
The default OpenTelemetry distro for Python sets the OTLP protocol to gRPC. If your backend takes OTLP over HTTP, as Fixter does, set OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf. The opentelemetry-exporter-otlp package includes both exporters, so nothing else needs installing.
Which Python version does OpenTelemetry need?
The current release, opentelemetry-sdk 1.45.2 from October 29, 2026, requires Python 3.10 or newer according to PyPI. Older Python versions need an older OpenTelemetry release.
Can my coding agent set up OpenTelemetry for my Python app?
Yes. Paste "Read fixter.dev/llms.txt and set up Fixter." into Claude Code, Cursor or another coding agent in your project. It adds standard OpenTelemetry to the app and points it at Fixter. Because it is standard OpenTelemetry, the same instrumentation works with any backend that accepts OTLP.
Sources (14), all checked November 13, 2026
- OpenTelemetry docs, Python zero-code instrumentation (install commands, opentelemetry-bootstrap, opentelemetry-instrument)
- OpenTelemetry docs, Python agent configuration (HTTP instead of gRPC, logging variables, excluded URLs)
- OpenTelemetry docs, Python logs auto-instrumentation example (on by default since 1.40.0)
- OpenTelemetry docs, Python troubleshooting (uv, Flask reloader, pre-fork servers and workers)
- opentelemetry-python-contrib v0.66b2, bootstrap_gen.py (libraries opentelemetry-bootstrap covers, default instrumentations)
- opentelemetry-python-contrib v0.66b2, opentelemetry-distro source (default exporters and protocol)
- opentelemetry-python-contrib v0.66b2, logging handler source (exception attributes, trace context on log records)
- PyPI, opentelemetry-sdk (version 1.45.2, October 29, 2026, requires Python 3.10 or newer)
- opentelemetry-python, Django example (DJANGO_SETTINGS_MODULE, runserver --noreload with auto-instrumentation)
- OpenTelemetry docs, Python getting started (opentelemetry-instrument with flask run)
- Fixter docs, Send data with OpenTelemetry (API key, four environment variables, Python recipe, environment name)
- Fixter docs, Issues (grouping, runtime tags, log errors, environments)
- Fixter, llms.txt (what the setup prompt tells your agent to do)
- opentelemetry-python-contrib v0.66b2, Django instrumentation source (reads DJANGO_SETTINGS_MODULE, falls back to empty settings)