Tracelit Python SDK
Drop-in OpenTelemetry SDK for Python that exports traces, metrics, and logs to Tracelit via OTLP/HTTP.
Install
pip install tracelit
Install OpenTelemetry instrumentation packages for your stack (see each framework section below). Tracelit only instruments libraries whose instrumentation package is installed — missing packages are skipped silently.
pip install opentelemetry-instrumentation-flask # Flask apps
pip install opentelemetry-instrumentation-django # Django apps
pip install opentelemetry-instrumentation-fastapi # FastAPI apps
pip install opentelemetry-instrumentation-celery # Celery workers
pip install opentelemetry-instrumentation-redis # Redis
pip install opentelemetry-instrumentation-requests # requests HTTP client
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. |
There is no
tracelit.init()API.
Django
1. Add to settings.py:
INSTALLED_APPS = [
"tracelit.integrations.django.TracelitConfig", # full path required
"django.contrib.admin",
# ...
]
2. Set environment variables (.env, deployment config, etc.):
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 Django (runserver, gunicorn, uvicorn, etc.).
Tracelit starts automatically in AppConfig.ready() after Django is configured.
python-decouple / django-environ
Bridge secrets into os.environ before INSTALLED_APPS:
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"))
Do not call
tracelit.auto_start()at the top ofsettings.py.
Celery (Django projects with background workers)
In celery.py:
from tracelit.integrations.celery import install_celery_hook
install_celery_hook()
pip install opentelemetry-instrumentation-celery
Flask
1. app.py — complete working example:
import os
import tracelit
tracelit.auto_start(
api_key=os.environ["TRACELIT_API_KEY"],
service_name="my-flask-app",
environment=os.getenv("FLASK_ENV", "production"),
)
from flask import Flask
from tracelit.integrations.wsgi import TracelitWSGIMiddleware
app = Flask(__name__)
app.wsgi_app = TracelitWSGIMiddleware(app.wsgi_app)
@app.get("/")
def home():
return "ok"
2. Install Flask instrumentation:
pip install opentelemetry-instrumentation-flask opentelemetry-instrumentation-wsgi
3. Run:
export TRACELIT_API_KEY=your-api-key
FLASK_APP=app.py flask run
FLASK_APP=app.py requires a module-level variable named app. If your factory is named differently, use FLASK_APP=app:create_app instead.
TracelitWSGIMiddleware adds HTTP request metrics. Flask route tracing comes from opentelemetry-instrumentation-flask.
FastAPI
1. main.py — complete working example:
import os
import tracelit
tracelit.auto_start(
api_key=os.environ["TRACELIT_API_KEY"],
service_name="my-api",
environment=os.getenv("ENV", "production"),
)
from fastapi import FastAPI
from tracelit.integrations.asgi import TracelitASGIMiddleware
app = FastAPI()
app = TracelitASGIMiddleware(app)
@app.get("/")
def home():
return {"ok": True}
2. Install FastAPI instrumentation:
pip install opentelemetry-instrumentation-fastapi opentelemetry-instrumentation-asgi
3. Run with uvicorn:
export TRACELIT_API_KEY=your-api-key
uvicorn main:app
Scripts and batch jobs (no web framework)
Use tracelit.auto_start() at the top of your entry point. This is for CLIs, cron jobs, and one-off scripts — not for Django (use TracelitConfig instead).
import os
import tracelit
tracelit.auto_start(
api_key=os.environ["TRACELIT_API_KEY"],
service_name="nightly-report",
environment=os.getenv("ENV", "production"),
)
with tracelit.tracer().start_as_current_span("generate-report"):
# your logic here
pass
Or rely entirely on environment variables:
import tracelit
tracelit.auto_start()
Manual spans and metrics
import tracelit
with tracelit.tracer().start_as_current_span("process-order"):
tracelit.metrics.counter("orders.processed").add(1)
Configuration
| Option | Env var | Default |
|---|---|---|
| api_key | TRACELIT_API_KEY |
required |
| service_name | TRACELIT_SERVICE_NAME |
unknown-service |
| environment | TRACELIT_ENVIRONMENT |
production |
| endpoint | TRACELIT_ENDPOINT |
https://ingest.tracelit.app |
| sample_rate | TRACELIT_SAMPLE_RATE |
1.0 |
| enabled | TRACELIT_ENABLED |
true |
Set TRACELIT_ENABLED=false in tests to disable telemetry with no code changes.
Behavior guarantees
- Non-blocking span export with async error-span queue
- Never raises setup or exporter failures into customer code
- Graceful shutdown flush at process exit
- Error spans are always exported, even when sampling is below
1.0 - Missing instrumentation packages are skipped silently (no startup warning spam)
Metadata
Release files for tracelit-python 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tracelit_python-0.1.1.tar.gz | 16.5 kB | With provenance | Details for tracelit_python-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tracelit_python-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for tracelit_python-0.1.1-py3-none-any.whl |
Total release size: 32.3 kB
Release files / tracelit_python-0.1.1.tar.gz
| Download URL | tracelit_python-0.1.1.tar.gz |
|---|---|
| Size | 16.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e7266dc203060be91c19cf90608fe24c118276f6e33e90ed0aaf35614c8ebd6c
|
|
BLAKE2b-256 checksum How to use checksums |
dc80ed69134c0e9ec18a7c406c6df01a52f1586cd165fcbcdceba9bda2149227
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 9, 2026.
Transparency logRelease files / tracelit_python-0.1.1-py3-none-any.whl
| Download URL | tracelit_python-0.1.1-py3-none-any.whl |
|---|---|
| Size | 15.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
35873ff425b482fdc733d0f0cc0576e2fb40233efb3801fd1cf88d1c463d73ad
|
|
BLAKE2b-256 checksum How to use checksums |
590680276058d2da93c9f3d0c872f50e3a18f6e5f045769f0e59f46ed527d050
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 9, 2026.
Transparency logSecurity for tracelit-python 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for tracelit_python-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 9, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.