Requirements: Python ≥ 3.10
Installation
Which setup do I use?
| App type | How to initialize Tracelit |
|---|---|
| Django | Add tracelit.integrations.django.TracelitConfig to INSTALLED_APPS. Do not call auto_start() in settings.py. |
| Flask | Call tracelit.auto_start() in app.py before routes run. Expose a module-level app object. |
| FastAPI | Call tracelit.auto_start() in main.py before the app serves traffic. |
| Celery worker | Call install_celery_hook() in celery.py. |
| Script / CLI / batch job | Call tracelit.auto_start() at process startup. |
Framework setup
- Django
- Flask
- FastAPI
- Scripts / CLI
Add Tracelit to INSTALLED_APPS
Use the full app config class — not Tracelit calls
tracelit.integrations.django alone.settings.py
auto_start() in AppConfig.ready() after Django is fully configured. Do not call tracelit.auto_start() yourself in settings.py.python-decouple / django-environ
Bridge secrets intoos.environ before INSTALLED_APPS:settings.py
Celery workers
Web server instrumentation does not cover Celery. Add tocelery.py:celery.py
Configuration reference
All options can be passed totracelit.auto_start(...) or set via environment variables.
| Option | Env variable | Default | Description |
|---|---|---|---|
api_key | TRACELIT_API_KEY | — | Required. Your Tracelit ingest API key |
service_name | TRACELIT_SERVICE_NAME | unknown-service | Service name shown in Tracelit |
environment | TRACELIT_ENVIRONMENT | "production" | Deployment environment tag |
endpoint | TRACELIT_ENDPOINT | https://ingest.tracelit.app | Override only when self-hosting |
sample_rate | TRACELIT_SAMPLE_RATE | 1.0 | Sampling ratio 0.0–1.0. Errors always export. |
enabled | TRACELIT_ENABLED | true | Set false to disable all telemetry in tests |
Custom resource attributes
Instrumentation packages
Tracelit instruments libraries only when the matchingopentelemetry-instrumentation-* package is installed. Uninstalled packages are skipped silently — no startup warning spam.
| Library | Package to install |
|---|---|
| Django | opentelemetry-instrumentation-django |
| Flask | opentelemetry-instrumentation-flask |
| FastAPI | opentelemetry-instrumentation-fastapi |
| PostgreSQL (psycopg2) | opentelemetry-instrumentation-psycopg2 |
| MySQL | opentelemetry-instrumentation-pymysql or opentelemetry-instrumentation-mysqlclient |
| Redis | opentelemetry-instrumentation-redis |
| Celery | opentelemetry-instrumentation-celery |
| HTTP clients | opentelemetry-instrumentation-requests, opentelemetry-instrumentation-httpx |
Tracing
Manual spans
Metrics
TracelitASGIMiddleware and TracelitWSGIMiddleware also record http.server.request.count, http.server.request.duration, and http.server.error.count per route.
Disabling in tests
Common mistakes
Calling tracelit.init()
Calling tracelit.init()
This function does not exist. Use
tracelit.auto_start() for Flask/FastAPI/scripts, or TracelitConfig for Django.Calling auto_start() at the top of settings.py (Django)
Calling auto_start() at the top of settings.py (Django)
Django is not ready yet. Use
tracelit.integrations.django.TracelitConfig in INSTALLED_APPS instead.FLASK_APP=app.py but Flask can't find the application
FLASK_APP=app.py but Flask can't find the application
Flask expects a module-level variable named
app. If you use a factory, set FLASK_APP=app:create_app.Only installing tracelit without instrumentation packages
Only installing tracelit without instrumentation packages
The SDK starts but won’t trace Django/Flask/Redis/etc. Install the matching
opentelemetry-instrumentation-* packages.Expecting Celery tasks to be traced from the web process
Expecting Celery tasks to be traced from the web process
Workers are separate processes. Call
install_celery_hook() in celery.py.