Skip to main content

Traces & Spans

What is a Trace?

A trace represents a complete unit of work — like handling a user request, processing a document, or running an agent workflow. Think of it as a timeline:
Each step in this timeline is a span. Together, all spans form the complete trace.

What is a Span?

A span represents a single operation within a trace — like an LLM call, tool execution, or retrieval step.

Span Types

See the JavaScript SDK or Python SDK for code examples of each span type.

Trace Hierarchy

Traces contain spans organized in a tree structure:

Best Practices

Create a new trace for each distinct user interaction. Don’t reuse trace IDs across requests.
Use names that describe the workflow: process-customer-query, generate-report, analyze-document.
Choose the span type that best represents the operation. This enables better filtering and analytics in the dashboard.
Token counts are essential for cost tracking and optimization.
Always call span.end() even on errors. Use try/finally or convenience methods like ctx.llmCall() for automatic handling.
Keep span depth reasonable (typically 3-5 levels max). Deep nesting makes traces hard to read.

Next Steps

Signals

Add feedback and metrics to traces

Alerting

Get notified on quality issues