Skip to content
GitHubLog inStart free
cetra is not released yet. These docs describe the development version.

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.

Terminal window
pip install "cetra-sdk[langchain]" langchain langchain-openai
import json
import os
import cetra
from langchain.agents import create_agent
from langchain.tools import tool
from langchain_core.messages import HumanMessage
from langchain_openai import ChatOpenAI
from pydantic import SecretStr
cetra.init(instrument=["langchain"])
@tool
def 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()

langchain.agents.create_agent (LangChain 1.x) and langgraph.prebuilt.create_react_agent produce the same graph spans.

  • A graph run is a LangGraph chain span as the trace root.
  • Each node is a chain span named after the node (model, tools), with the model calls and the tool calls under their nodes.
  • Each model call is an llm span with the messages, the tool definitions, the token counts and the cost, computed from the built-in prices.
  • Each tool call is a tool span with the tool’s input and output.
  • LangGraph’s own keys, such as langgraph_node and langgraph_step, stay in the span’s metadata.
  • With OpenLLMetry, the graph and its nodes come out as agent and chain spans with the provider langgraph.
  • 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 langchain 1.4.8, langchain-openai 1.7.3 and langgraph 1.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.