Skip to main content
Available for: Python and TypeScript.
The ZespanCallbackHandler integrates with LangChain’s callback system to automatically capture every LLM call, tool invocation, chain step, and retrieval operation as linked spans in Zespan. You pass it once and it instruments the entire execution graph — no changes to your chain or agent logic are needed.

How it works

LangChain calls lifecycle methods on every registered BaseCallbackHandler at each stage of execution. The Zespan handler subscribes to: All events share the same trace_id so you see the entire chain as a single flame graph in the Traces view.

TypeScript

Installation

Basic usage

Chains

Pass the handler to RunnableSequence or any chain using the config argument:

Agents and tools

The handler captures the full agent loop: plan → tool call → observation → next plan. Each iteration appears as linked spans.

RAG with retriever tracing


Python

Installation

Basic usage

Chains

Agents


How traces look in the dashboard

A LangChain agent run produces a trace like this in the flame graph:
Each row is a span. The total trace cost is the sum of both LLM spans. Tool call spans show the tool name and execution time but have no token cost.
To associate a LangChain trace with a user session, wrap the chain invocation in withZespanContext:

Guardrails with LangChain

Pass guardrail options to ZespanCallbackHandler to enable pre/post content checks on LLM calls made by the chain: