Skip to main content
Cascade uses OpenTelemetry under the hood to capture a full execution tree of your agent: every LLM call, tool invocation, sub-agent delegation, and function, captured as a hierarchical trace.

Initialize tracing

Call init_tracing() once at the top of your application. Everything else is automatic.

Trace a run

Wrap your agent’s entry point with trace_run() to create the root span. Any execution triggered from within the block is captured—including LLM calls, tool invocations, and sub-agent delegations that occur in nested functions or framework code. For example, if your agent logic lives in a single call (e.g. plan = planner.run(task)), placing that call inside trace_run is enough; everything inside run() is traced as child spans.

Trace sub-agents

If you have multiple agents or sub-agents, use trace_agent() to create a named sub-agent span. All tool calls and LLM calls inside the block are automatically tagged with the agent name.

Trace multi-turn sessions

For multi-turn conversations, group traces under a session so they appear together in the dashboard. Create a session ID, call set_session_id() to set it in context, and call end_session() when the conversation ends. Example:
Each trace_run() inherits the session ID from context.

Trace tools

Decorate any function with @tool to trace it as a tool call. Works with both sync and async functions.
The @tool decorator automatically records:
  • Input parameters
  • Output value
  • Execution time
  • Errors (with full exception info)

Trace functions

Use @function for internal utility functions that support your tools. These appear as distinct “function” spans in the trace tree.

Wrap LLM clients

Use wrap_llm_client() to automatically trace every LLM call (prompts, completions, token counts, latency, and cost) with zero changes to your existing code.

What gets captured per LLM call

Streaming support

Streaming is fully supported for both Anthropic and OpenAI:

Full example

A complete example combining all tracing features: