Skip to content
TraceStax Docs

Python

The TraceStax Python SDK supports Celery, Dramatiq, and RQ. One package, multiple integrations — use whichever submodule matches your queue.

  • Python 3.9+
  • One of: Celery 5.x, Dramatiq 1.x, RQ 1.x
Terminal window
pip install tracestax

from celery import Celery
from tracestax import configure
app = Celery("myapp", broker="redis://localhost:6379/0")
configure(app, api_key="ts_live_xxxxxxxxxxxx")

configure() attaches to Celery’s signal system automatically — no changes to your task definitions required.

Django + Celery:

myproject/celery.py
import os
from celery import Celery
from tracestax import configure
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
app = Celery("myproject")
app.config_from_object("django.conf:settings", namespace="CELERY")
app.autodiscover_tasks()
configure(app, api_key=os.environ["TRACESTAX_API_KEY"])

Enable duration tracking — set this in your Celery config or it will default on:

app.conf.task_track_started = True

All options can be passed as keyword arguments to configure() or set via environment variables.

OptionEnv varDefaultDescription
api_keyTRACESTAX_API_KEYRequired. Project API key
endpointTRACESTAX_INGEST_URLhttps://ingest.tracestax.comOverride for proxying or self-hosted
enabledTRACESTAX_ENABLEDtrueSet to false to disable ingest (e.g. in tests)
flush_interval5.0Seconds between background flushes
max_batch_size100Max events per HTTP request
enable_lineagetrueTrack task chains and parent/child relationships (Celery only)
enable_snapshotstruePeriodically snapshot queue depth (Celery only)

@app.task(tracestax={"tags": ["critical", "payments"]})
def process_payment(order_id: int):
...

Set TRACESTAX_ENABLED=false in your test environment:

# pytest conftest.py
import os
os.environ.setdefault("TRACESTAX_ENABLED", "false")

For Celery, task_always_eager suppresses signals so events won’t fire anyway — but being explicit is good practice.


Events not appearing after deploy

Check your worker process can reach ingest.tracestax.com:443. Ingest calls are made in a background thread and will log a warning if they fail — check your worker logs.

Duration showing as 0 (Celery)

task_track_started = True must be set in your Celery config. Without it the task_started signal doesn’t fire and duration can’t be calculated.

High event volume

The SDK batches events and flushes asynchronously. If you’re processing thousands of tasks per second, increase max_batch_size in configure() and ensure your workers have outbound HTTPS access.