LangGraph
Trace LangGraph graphs with cetra from Python and TypeScript, through the OpenInference LangChain instrumentation. The one langchain instrumentor covers LangChain, LangGraph and Deep Agents; see LangChain and Deep Agents.
Install
Section titled “Install”pip install "cetra-sdk[langchain]" langchain langchain-openainpm install @cetra-ai/sdk @arizeai/openinference-instrumentation-langchain @langchain/core @langchain/openaiSet up
Section titled “Set up”import jsonimport os
import cetrafrom langchain.agents import create_agentfrom langchain.tools import toolfrom langchain_core.messages import HumanMessagefrom langchain_openai import ChatOpenAIfrom pydantic import SecretStr
cetra.init(instrument=["langchain"])
@tooldef get_weather(city: str) -> str: """Look up the weather for a city.""" return json.dumps({"temperature_c": 18, "conditions": "sunny", "city": city})
model = ChatOpenAI(model="gpt-4o-mini", api_key=SecretStr(os.environ["OPENAI_API_KEY"]))agent = create_agent( model, tools=[get_weather], system_prompt="You are a weather assistant.",)agent.invoke({"messages": [HumanMessage("What's the weather in Paris?")]})
cetra.flush()import { init } from "@cetra-ai/sdk";import { langchain } from "@cetra-ai/sdk/langchain";import * as callbacksManager from "@langchain/core/callbacks/manager";init({ apiKey: process.env.CETRA_API_KEY, instrument: [langchain(callbacksManager)] });import { ChatOpenAI } from "@langchain/openai";
const model = new ChatOpenAI({ model: "gpt-4o-mini" });await model.invoke("What is the weather in Paris?");langchain.agents.create_agent (LangChain 1.x) and langgraph.prebuilt.create_react_agent produce the same graph spans.
What you get
Section titled “What you get”- A graph run is a
LangGraphchainspan as the trace root. - Each node is a
chainspan named after the node (model,tools), with the model calls and the tool calls under their nodes. - Each model call is an
llmspan with the messages, the tool definitions, the token counts and the cost, computed from the built-in prices. - Each tool call is a
toolspan with the tool’s input and output.
Limits
Section titled “Limits”- LangGraph’s own keys, such as
langgraph_nodeandlanggraph_step, stay in the span’s metadata. - With OpenLLMetry, the graph and its nodes come out as
agentandchainspans with the providerlanggraph. - The TypeScript helper is covered by an SDK test that builds the instrumentation from LangChain’s callback module. No spans of a LangGraph.js run are captured.
- The fixtures were captured in Python with
langchain1.4.8,langchain-openai1.7.3 andlanggraph1.2.19, with OpenInference 0.1.81 and OpenLLMetry 0.62.4. - If a field is missing, look at the span’s Attributes tab and compare it with Span attributes.
- Traces: read the trace as a tree and a timeline.
- Cost and tokens: how cost is computed from the token counts.
- Online rules: score these traces automatically.