Setup
Unlike OpenAI/Anthropic instrumentation which patches globally, LangChain requires explicitly passing the callback handler to your components.
Basic Usage
Pass the handler to your LangChain calls via theconfig parameter:
Using get_callback_config
For convenience, useget_callback_config() to get a pre-configured dict:
Using instrument (Singleton)
Useinstrument() to get a global singleton handler:
Chains
Trace entire chain executions with parent-child relationships:Tools
Tool invocations are automatically traced:Retrievers
RAG retriever operations are traced:Trace Structure
The callback handler creates nested spans showing the full execution tree:Captured Data
The integration traces:| Component | Captured Data |
|---|---|
| LLM | Model, prompts, completions, tokens, latency |
| Chain | Chain type, inputs, outputs, duration |
| Tool | Tool name, input, output, duration |
| Retriever | Query, retrieved documents, duration |

