Skip to main content
Requirements: Python ≥ 3.10

Installation

pip install tracelit
Install OpenTelemetry instrumentation packages for your stack (see each tab below). Missing packages are skipped silently at startup.

Which setup do I use?

There is no tracelit.init() API.
App typeHow to initialize Tracelit
DjangoAdd tracelit.integrations.django.TracelitConfig to INSTALLED_APPS. Do not call auto_start() in settings.py.
FlaskCall tracelit.auto_start() in app.py before routes run. Expose a module-level app object.
FastAPICall tracelit.auto_start() in main.py before the app serves traffic.
Celery workerCall install_celery_hook() in celery.py.
Script / CLI / batch jobCall tracelit.auto_start() at process startup.

Framework setup

1

Add Tracelit to INSTALLED_APPS

Use the full app config class — not tracelit.integrations.django alone.
settings.py
INSTALLED_APPS = [
    "tracelit.integrations.django.TracelitConfig",
    "django.contrib.admin",
    # ...
]
Tracelit calls auto_start() in AppConfig.ready() after Django is fully configured. Do not call tracelit.auto_start() yourself in settings.py.
2

Set environment variables

.env
TRACELIT_API_KEY=your-api-key
TRACELIT_SERVICE_NAME=payments-api
TRACELIT_ENVIRONMENT=production
TRACELIT_ENDPOINT=https://ingest.tracelit.app
3

Install Django instrumentation

pip install opentelemetry-instrumentation-django
4

Restart and verify

python manage.py runserver
Hit any endpoint and confirm traces appear in the Tracelit dashboard.

python-decouple / django-environ

Bridge secrets into os.environ before INSTALLED_APPS:
settings.py
import os
from decouple import config

os.environ.setdefault("TRACELIT_API_KEY", config("TRACELIT_API_KEY"))
os.environ.setdefault("TRACELIT_SERVICE_NAME", config("TRACELIT_SERVICE_NAME", default="backend"))
os.environ.setdefault("TRACELIT_ENVIRONMENT", config("TRACELIT_ENVIRONMENT", default="production"))
os.environ.setdefault("TRACELIT_ENDPOINT", config("TRACELIT_ENDPOINT", default="https://ingest.tracelit.app"))

Celery workers

Web server instrumentation does not cover Celery. Add to celery.py:
celery.py
from tracelit.integrations.celery import install_celery_hook

install_celery_hook()
pip install opentelemetry-instrumentation-celery

Configuration reference

All options can be passed to tracelit.auto_start(...) or set via environment variables.
OptionEnv variableDefaultDescription
api_keyTRACELIT_API_KEYRequired. Your Tracelit ingest API key
service_nameTRACELIT_SERVICE_NAMEunknown-serviceService name shown in Tracelit
environmentTRACELIT_ENVIRONMENT"production"Deployment environment tag
endpointTRACELIT_ENDPOINThttps://ingest.tracelit.appOverride only when self-hosting
sample_rateTRACELIT_SAMPLE_RATE1.0Sampling ratio 0.01.0. Errors always export.
enabledTRACELIT_ENABLEDtrueSet false to disable all telemetry in tests

Custom resource attributes

import tracelit

tracelit.auto_start(
    api_key="...",
    service_name="orders-api",
    resource_attributes={
        "deployment.region": "us-east-1",
        "team": "platform",
    },
)

Instrumentation packages

Tracelit instruments libraries only when the matching opentelemetry-instrumentation-* package is installed. Uninstalled packages are skipped silently — no startup warning spam.
LibraryPackage to install
Djangoopentelemetry-instrumentation-django
Flaskopentelemetry-instrumentation-flask
FastAPIopentelemetry-instrumentation-fastapi
PostgreSQL (psycopg2)opentelemetry-instrumentation-psycopg2
MySQLopentelemetry-instrumentation-pymysql or opentelemetry-instrumentation-mysqlclient
Redisopentelemetry-instrumentation-redis
Celeryopentelemetry-instrumentation-celery
HTTP clientsopentelemetry-instrumentation-requests, opentelemetry-instrumentation-httpx
Disable specific instrumentations:
OTEL_PYTHON_DISABLED_INSTRUMENTATIONS=sqlite3,asyncio,logging

Tracing

Manual spans

import tracelit

with tracelit.tracer().start_as_current_span("process_payment") as span:
    span.set_attribute("payment.id", payment_id)
    span.set_attribute("payment.amount", amount)
    process(payment)

Metrics

import tracelit

counter = tracelit.metrics.counter("orders.created", unit="{order}")
counter.add(1, {"plan": "pro"})
TracelitASGIMiddleware and TracelitWSGIMiddleware also record http.server.request.count, http.server.request.duration, and http.server.error.count per route.

Disabling in tests

TRACELIT_ENABLED=false pytest

Common mistakes

This function does not exist. Use tracelit.auto_start() for Flask/FastAPI/scripts, or TracelitConfig for Django.
Django is not ready yet. Use tracelit.integrations.django.TracelitConfig in INSTALLED_APPS instead.
Flask expects a module-level variable named app. If you use a factory, set FLASK_APP=app:create_app.
The SDK starts but won’t trace Django/Flask/Redis/etc. Install the matching opentelemetry-instrumentation-* packages.
Workers are separate processes. Call install_celery_hook() in celery.py.

Source

github.com/Tracelit-AI/tracelit-python