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
Attach the Respan LangChain callback to the runnable config for each chain, model, tool, retriever, or agent run you want traced.
For a provider-backed model, keep the same callback config and swap in your model:
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 callback spans are emitted when you attach the Respan callback config. 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.