LangChain (tracing)
LangChain (tracing)
LangChain is a framework for building applications with language models. It provides chains, agents, tools, retrievers, and provider integrations. Respan gives you full observability over every chain run, agent step, retriever call, tool call, and LLM generation — and gateway routing through the OpenAI-compatible Respan endpoint.
Set up Respan
Create an account at platform.respan.ai and grab an API key.
Run npx @respan/cli setup to set up with your coding agent.
Use Respan Gateway
See LangChain gateway setup to route this integration through the Respan gateway.
Example projects
Setup
Set environment variables
RESPAN_API_KEY is used to export traces to Respan. Set OPENAI_API_KEY too when your LangChain run uses a provider-backed model instead of a fake/local model.
Initialize and run
Pass LangChainInstrumentor() to Respan(instrumentations=[...]). The instrumentor captures every chain, model, tool, retriever, and agent run.
Python — the instrumentor patches LangChain’s callback manager on init, so every run (chains, agents, graphs, and their nested LLM, tool, and retriever calls) is traced automatically. No per-call setup.
TypeScript — the instrumentor does not patch globally. Attach langchain.addCallback(...) at the outermost .invoke() (your chain, agent, or graph); LangChain propagates it to nested runs. Attaching it only to an inner model yields just that one LLM span.
Optionally attach a callback config to label a specific run with a run_name, tags, or metadata. In Python this is only for labeling — tracing already happens through the instrumentor. In TypeScript it is also what activates tracing for the run.
View your trace
Open the Traces page to see your LangChain workflow with chain runs, LLM calls, retriever spans, and tool calls.
Configuration
Attributes
In Respan()
Set defaults at initialization — these apply to all spans.
With propagate_attributes
Override per-request using a context scope.
Decorators (optional)
Decorators are not required. LangChain spans are emitted automatically by the instrumentor in Python, and when you attach the Respan callback config in TypeScript. Use @workflow and @task (Python) or withWorkflow and withTask (TypeScript) to add structure when you want to group related runs into a named workflow with nested tasks.
Examples
Chains
Chains are traced as workflow/task spans with nested LLM and tool spans.
Tools
Tool calls are captured with tool name, arguments, result, and timing.
Streaming
Streaming responses are traced like regular calls.