Skip to main content

Installation

pip install -e ./sdk/tracectrl
pip install -e ./sdk/tracectrl-instrumentation-langchain

Usage

import tracectrl
tracectrl.configure(service_name="my-langchain-agent")

from tracectrl.instrumentation.langchain import LangChainInstrumentor
LangChainInstrumentor().instrument()

# Your LangChain code — no changes needed
from langchain_openai import ChatOpenAI
from langchain.agents import create_openai_tools_agent, AgentExecutor

llm = ChatOpenAI(model="gpt-4o")
# ... define tools, prompt, agent
agent_executor.invoke({"input": "Summarize my latest emails"})

What Gets Captured

Span KindExamplesAttributes Set
CHAINChain/pipeline runsinput.value, output.value
LLMChatOpenAI, ChatAnthropicllm.model_name, llm.system
TOOLTool invocationstool.name, tool.description, tracectrl.tool.category
AGENTAgentExecutor runstracectrl.agent.id, tracectrl.agent.name
RETRIEVERVector store retrievalsretrieval.documents

LangGraph Support

LangGraph agents are automatically captured — each node execution appears as a span with parent-child relationships matching the graph structure.
from langgraph.graph import StateGraph

graph = StateGraph(MyState)
graph.add_node("researcher", researcher_node)
graph.add_node("writer", writer_node)
# Each node creates spans that TraceCtrl enriches

API

LangChainInstrumentor()

instrument
method
instrument(tracer_provider=None, skip_dep_check=False) — Registers the TraceCtrl span processor and wraps the OpenInference LangChain instrumentor.
uninstrument
method
uninstrument() — Shuts down processors and unwraps the instrumentor.
instrumented
bool
Whether the instrumentor is currently active.