« All posts

Tracing Async AI Agents: Manual OpenTelemetry Propagation with SigNoz

How to fix broken OpenTelemetry traces in async AI agent pipelines using manual context propagation and SigNoz, from queue to LLM call.

Standard HTTP auto-instrumentation stops working the moment an AI agent task is handed off to a background queue like Redis/Celery, breaking the trace context and leaving engineers to manually correlate disconnected log lines. A detailed approach shows how to fix this by manually injecting and extracting OpenTelemetry trace context across the queue boundary, so background worker spans nest correctly under the originating API request.

The pattern also covers instrumenting the LLM call itself with custom span attributes—model name, token counts, latency, and provider—turning opaque 'black box' API calls into queryable telemetry. Paired with SigNoz for visualization, this produces a full Gantt-style trace tree spanning the FastAPI request, the Celery worker, vector DB retrieval, and the LLM generation step.

For teams building latency-sensitive pipelines—real-time risk scoring, hallucination detection, or multi-step agent orchestration—this closes an observability gap that generic OpenTelemetry setup guides don't address, making it possible to pinpoint whether slowdowns originate in retrieval, orchestration, or the model provider.