LangChain
cetra traces LangChain and LangGraph runs as a tree: the graph, its nodes, each model call and each tool call. For LangGraph graphs and Deep Agents, see LangGraph 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 cetrafrom langchain_openai import ChatOpenAI
cetra.init(instrument=["langchain"])
model = ChatOpenAI(model="gpt-4o-mini")model.invoke("What is 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?");What you get
Section titled “What you get”- A chat model call is an
llmspan with the provider, the messages, the tool definitions and the token counts. - A tool run is a
toolspan. - A LangGraph agent is a tree: the graph, each node as a
chainspan, the model calls and the tool calls under their nodes. - LangChain’s run metadata, such as
langgraph_nodeandlanggraph_step, is kept as span metadata. - Cost is computed from the token counts of each model call.
LangServe
Section titled “LangServe”LangServe serves LangChain runnables over HTTP and has no spans of its own. Instrument the app’s LangChain code as this page shows, and add an OpenTelemetry FastAPI instrumentor for the HTTP layer if you want HTTP spans.
Limits
Section titled “Limits”- 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. - 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 LangChain.js run are captured.
- 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.