Skip to main content

A lightweight Celery task flow visualizer

Project description

stemtrace ๐ŸŒฟ

Zero-infrastructure Celery task flow visualizer

PyPI version Python CI codecov License: MIT Code style: ruff Type checked: mypy


Flower answers "what exists". stemtrace answers "what happened".

stemtrace models Celery as a graph of executions derived from events. Visualize task flows, timelines, retries, and parent-child relationships โ€” using your existing broker with zero new infrastructure.

โœจ Features

  • Task Flow Graphs โ€” Visualize parent โ†’ child chains, groups, and chords as DAGs
  • Canvas Awareness โ€” Synthetic GROUP nodes for group() and chord() visualization
  • Execution Timeline โ€” See queued โ†’ received โ†’ started โ†’ retried โ†’ finished states
  • Full Lifecycle Capture โ€” PENDING, RECEIVED, STARTED, RETRY, SUCCESS, FAILURE states
  • Arguments & Results โ€” View task inputs and outputs with sensitive data scrubbing
  • Exception Capture โ€” Full traceback visibility on retries and failures
  • Task Registry โ€” Browse all discovered task definitions
  • Timing Visibility โ€” Start time and duration shown directly in graph nodes
  • Correlation Tracking โ€” Trace requests across multiple tasks via trace_id
  • Retry Visibility โ€” Know exactly which retries happened and why
  • Zero Infrastructure โ€” Uses your existing broker; no database required
  • Broker-Agnostic โ€” Works with Redis, RabbitMQ, and other Celery brokers
  • FastAPI Pluggable โ€” Mount directly into your existing FastAPI app
  • Zero Config โ€” Auto-detects your Celery broker configuration
  • Read-Only โ€” Safe for production; never modifies your task queue

๐Ÿš€ Quick Start

1. Install

pip install stemtrace

2. Instrument your Celery app

from celery import Celery
import stemtrace

app = Celery("myapp", broker="redis://localhost:6379/0")

# One line to enable flow tracking
stemtrace.init(app)

3. Run the visualizer

stemtrace server

Open http://localhost:8000 and watch your task flows come alive.

By default, connects to redis://localhost:6379/0. Override with --broker-url or STEMTRACE_BROKER_URL env var.

See Deployment Options for FastAPI integration and production setups.

๐Ÿ“ฆ Architecture

stemtrace is designed as two decoupled components:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                        Your Application                          โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”        โ”‚
โ”‚  โ”‚ Celery Workerโ”‚    โ”‚ Celery Workerโ”‚    โ”‚ Celery Workerโ”‚        โ”‚
โ”‚  โ”‚ + stemtrace  โ”‚    โ”‚ + stemtrace  โ”‚    โ”‚ + stemtrace  โ”‚        โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜        โ”‚
โ”‚         โ”‚                   โ”‚                   โ”‚                โ”‚
โ”‚         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                โ”‚
โ”‚                             โ”‚ events                             โ”‚
โ”‚                             โ–ผ                                    โ”‚
โ”‚                     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                            โ”‚
โ”‚                     โ”‚    Broker     โ”‚                            โ”‚
โ”‚                     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                            โ”‚
โ”‚                             โ”‚                                    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚
                              โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚    stemtrace      โ”‚
                    โ”‚  server (viewer)  โ”‚
                    โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
                    โ”‚  โ”‚   Web UI    โ”‚  โ”‚
                    โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Library (stemtrace)

  • Hooks into Celery signals
  • Captures task lifecycle events
  • Sends normalized events to the broker
  • Zero overhead in critical path โ€” fire-and-forget writes

Server (stemtrace server)

  • Reads events from the broker
  • Builds task graphs
  • Serves the web UI
  • Completely read-only โ€” safe for production

๐Ÿ”ง Configuration

Library Options

import stemtrace

stemtrace.init(
    app,
    # Optional: override broker URL (defaults to Celery's broker_url)
    transport_url="redis://localhost:6379/0",
    prefix="stemtrace",                        # Key/queue prefix
    ttl=86400,                                 # Event TTL in seconds (default: 24h)

    # Data capture (all enabled by default)
    capture_args=True,                         # Capture task args/kwargs
    capture_result=True,                       # Capture return values

    # Sensitive data scrubbing (Sentry-style)
    scrub_sensitive_data=True,                 # Scrub passwords, API keys, etc.
    additional_sensitive_keys=frozenset({"my_secret"}),  # Add custom keys
    safe_keys=frozenset({"public_key"}),       # Never scrub these keys
)

# Introspection (after init)
stemtrace.is_initialized()   # -> True
stemtrace.get_config()       # -> StemtraceConfig
stemtrace.get_transport()    # -> EventTransport (for testing)

Sensitive Data Scrubbing

By default, stemtrace scrubs common sensitive keys from task arguments:

  • Passwords: password, passwd, pwd, secret
  • API keys: api_key, apikey, token, bearer, authorization
  • Financial: credit_card, cvv, ssn
  • Session: cookie, session, csrf

Scrubbed values appear as [Filtered] in the UI.

Canvas Graph Visualization

stemtrace automatically detects and visualizes Celery canvas constructs:

# Parent-spawned group: GROUP is child of parent
batch_processor
โ””โ”€โ”€ โ”Œโ”€ GROUP โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚  โ”œโ”€โ”€ add(1, 2)   โ”‚
    โ”‚  โ”œโ”€โ”€ add(3, 4)   โ”‚
    โ”‚  โ””โ”€โ”€ add(5, 6)   โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

# Standalone group: GROUP is a root node
โ”Œโ”€ GROUP โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  โ”œโ”€โ”€ add(1, 1)   โ”‚
โ”‚  โ”œโ”€โ”€ add(2, 2)   โ”‚
โ”‚  โ””โ”€โ”€ add(3, 3)   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

# Chord: header tasks inside, callback outside with edges
โ”Œโ”€ CHORD โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  โ”œโ”€โ”€ add(10, 10) โ”‚โ”€โ”€โ”
โ”‚  โ”œโ”€โ”€ add(20, 20) โ”‚โ”€โ”€โ”ผโ”€โ”€โ–บ aggregate_results
โ”‚  โ””โ”€โ”€ add(30, 30) โ”‚โ”€โ”€โ”˜
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  • Synthetic containers โ€” GROUP/CHORD nodes are always created when 2+ tasks share a group_id
  • Parent linking โ€” When spawned from a parent task, the container becomes a child of that parent
  • Chord callbacks โ€” Rendered outside the container with edges from each header task
  • Timing โ€” Each node displays start time and duration directly in the graph
  • Aggregate state โ€” Container shows running/success/failure based on member states

Environment Variables

Variable Description Default
STEMTRACE_BROKER_URL Broker connection URL Auto-detect from Celery
STEMTRACE_TTL Event TTL in seconds 86400
STEMTRACE_PREFIX Key/queue prefix stemtrace

Supported Brokers

Broker URL Scheme Status
Redis redis://, rediss:// โœ… Supported
RabbitMQ amqp://, amqps:// ๐Ÿšง Planned
Amazon SQS sqs:// ๐Ÿšง Planned

๐Ÿณ Docker

# With Redis
docker run -p 8000:8000 \
    -e STEMTRACE_BROKER_URL=redis://host.docker.internal:6379/0 \
    ghcr.io/stemtrace/server

# With RabbitMQ
docker run -p 8000:8000 \
    -e STEMTRACE_BROKER_URL=amqp://guest:guest@host.docker.internal:5672/ \
    ghcr.io/stemtrace/server

Or with Docker Compose:

services:
  stemtrace:
    image: ghcr.io/stemtrace/server
    ports:
      - "8000:8000"
    environment:
      - STEMTRACE_BROKER_URL=redis://redis:6379/0

๐Ÿ–ฅ๏ธ Deployment Options

stemtrace offers two deployment modes depending on your needs:

Mode Best For Command
Standalone Server Dedicated monitoring, simple setup stemtrace server
FastAPI Embedded Single-app deployment, existing FastAPI apps StemtraceExtension

Option 1: Standalone Server (Recommended)

The simplest way to run stemtrace โ€” a dedicated monitoring service:

pip install stemtrace

stemtrace server

Open http://localhost:8000 to view the dashboard.

Server Options

stemtrace server \
    --broker-url redis://myredis:6379/0 \
    --host 0.0.0.0 \
    --port 8000 \
    --reload  # For development

High-Scale Production Setup

For high-throughput environments, run the consumer separately from the web server:

# Terminal 1: Run consumer (processes events)
stemtrace consume

# Terminal 2: Run API server (separate process, shares state via broker)
stemtrace server

Option 2: FastAPI Embedded

Mount stemtrace directly into your existing FastAPI application:

from fastapi import FastAPI
from stemtrace.server import StemtraceExtension

flow = StemtraceExtension(broker_url="redis://localhost:6379/0")
app = FastAPI(lifespan=flow.lifespan)
app.include_router(flow.router, prefix="/stemtrace")

Access the dashboard at /stemtrace/ within your app.

With Custom Authentication

Use your existing auth middleware:

from fastapi import Depends
from stemtrace.server import StemtraceExtension
from your_app.auth import require_admin

flow = StemtraceExtension(
    broker_url="redis://localhost:6379/0",
    auth_dependency=Depends(require_admin),
)
app = FastAPI(lifespan=flow.lifespan)
app.include_router(flow.router, prefix="/stemtrace")

Or use built-in auth helpers:

from stemtrace.server import StemtraceExtension, require_basic_auth

flow = StemtraceExtension(
    broker_url="redis://localhost:6379/0",
    auth_dependency=require_basic_auth("admin", "secret"),
)
app = FastAPI(lifespan=flow.lifespan)
app.include_router(flow.router, prefix="/stemtrace")

Embedded Consumer Modes

Mode Use Case Setup
Embedded Development, simple apps Default โ€” consumer runs in FastAPI process
External Production, high scale Run stemtrace consume separately

๐Ÿ—บ๏ธ Roadmap

Completed

  • Task lifecycle tracking via signals
  • Broker-agnostic event transport (Redis Streams)
  • FastAPI pluggable integration
  • React SPA dashboard with real-time WebSocket updates
  • Task flow graph visualization
  • Execution timeline view
  • Task args/kwargs capture with sensitive data scrubbing
  • Exception and traceback capture
  • Task registry (browse all discovered tasks)
  • PENDING/RECEIVED state capture
  • E2E test suite (Docker API tests + Playwright browser tests)
  • Canvas graph reconstruction (group_id capture, synthetic GROUP/CHORD nodes)
  • Chord callback linking (CHORD node โ†’ callback edge)
  • Timing display in graph nodes (start time, duration)

Planned

  • Worker/queue tracking in events
  • Monitoring APIs (workers, stats, orphan detection)
  • UI reorganization (Dashboard, unified Executions, enhanced Registry)
  • RabbitMQ transport
  • OpenTelemetry export
  • Webhook event export
  • JSON export API

๐Ÿค Contributing

Contributions are welcome! Please read our Contributing Guide first.

# Clone the repo
git clone https://github.com/iansokolskyi/stemtrace.git
cd stemtrace

# Install dependencies (requires uv)
uv sync --all-extras

# Run checks
make check

๐Ÿ“„ License

MIT License โ€” see LICENSE for details.


stemtrace is not affiliated with the Celery project. Celery is a trademark of Ask Solem.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stemtrace-0.1.0.tar.gz (285.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stemtrace-0.1.0-py3-none-any.whl (300.2 kB view details)

Uploaded Python 3

File details

Details for the file stemtrace-0.1.0.tar.gz.

File metadata

  • Download URL: stemtrace-0.1.0.tar.gz
  • Upload date:
  • Size: 285.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for stemtrace-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b922191ab142ac9963b5ef46776d5f0f79907fafe33f03791723af30dc235d99
MD5 2dc1adc55ec3ea305339be6c5f99a6cc
BLAKE2b-256 13d577849a67c67564f38c153a9fa4159c2f7c4fe51ed3f3e557f025c74d262b

See more details on using hashes here.

File details

Details for the file stemtrace-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: stemtrace-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 300.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for stemtrace-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 07fb072571dac34700e1642fdb9212420d5a5604567d7ce841bcd28b18d2bb99
MD5 1dd0af563f84ab638bd38182e6600ee8
BLAKE2b-256 5dd59cb302cc3005c3d6013efab7ae039fdef8be1776a57808fbb08f6c51db09

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page