LangChain

LangChain Integration

Drop-in callback handler for LangChain and LangChain.js. Every chain step, LLM call, retriever, and tool invocation is traced with no code restructuring.

LangChain is a framework for building LLM-powered applications — chains, agents, retrievers, and tools — available for Python and JavaScript/TypeScript.

zespan.com — langchain trace
Zespan trace showing a LangChain chain run with steps, LLM call, and tool invocations

Getting Started

1

Install the SDK

Install @zespan/sdk alongside langchain.

bash
npm install @zespan/sdk langchain @langchain/openai
2

Add the callback handler

Pass LumiqCallbackHandler to any chain, agent, or LLM as a callback. No restructuring — it attaches to your existing LangChain code.

typescript
import { LumiqCallbackHandler } from '@zespan/sdk';
import { ChatOpenAI } from '@langchain/openai';
import { ConversationChain } from 'langchain/chains';

const handler = new LumiqCallbackHandler({
  apiKey: process.env.ZESPAN_API_KEY,
});

const model = new ChatOpenAI({ callbacks: [handler] });
const chain = new ConversationChain({ llm: model });

const result = await chain.invoke({ input: 'Tell me a joke' });
3

View traces in Zespan

Open Trace Explorer. Each chain run appears as a trace with nested spans for every step, LLM call, and tool invocation.

What's captured automatically

  • Full chain waterfall: every step, LLM call, retriever, and tool as linked spans
  • Agent reasoning: thought, action, and observation per ReAct step
  • Token and cost attribution: aggregated across every step in the chain
  • Retrieval spans: retrieved documents, scores, and chunk counts for RAG chains
  • LangGraph support: each graph node captured as a span
  • Error attribution: failures attributed to the correct chain step

FAQ

Does this work with LangGraph?

Yes. LumiqCallbackHandler works with LangGraph workflows. Each node in the graph is captured as a span, and the full execution graph is visible in the trace waterfall.

Do I need to restructure my existing chains?

No. Pass the handler to the callbacks parameter on any existing chain, agent, or LLM. Nothing else changes.

Does this work with LCEL (LangChain Expression Language)?

Yes. Pass the handler to the config parameter when invoking LCEL chains: chain.invoke(input, { callbacks: [handler] }).

Start for free — 10K traces/month, no card needed

LangChain integration works on all plans including the free tier.

← All integrations