Skip to main content

Installation

Setup

Python
We recommend using UUIDs for session_id and user_id so traces can be grouped reliably across runs.

Usage

Pass the handler via LangChain’s config["callbacks"]:
Python
TypeScript
Unlike other integrations, LangGraph does not use the instrument() pattern. You must pass the handler in config for each invocation.

What gets traced

Token usage

Token usage is extracted from LangChain’s usage_metadata (primary) or legacy llm_output.token_usage (fallback). The mapping is: input_tokens → prompt_tokens, output_tokens → completion_tokens. Reasoning tokens are subtracted from output_tokens when present.

Example

The Python example builds a ReAct agent using LangGraph with two tools. We trace the agent via LangGraphCallbackHandler:
Python
TypeScript
The Python example produces a trace with: CHAIN (root) → LLM (model call) → TOOL (get_weather) → TOOL (get_population) → LLM (final response).