LangSmith for LangChain/LangGraph-Native Tracing
LangSmith is the native observability surface for LangChain and LangGraph. When tracing is enabled, graph nodes, model calls, and tools nest under one run so you can see which branch fired, not only that the agent finished.
Use this page when your runtime is already LangGraph-shaped and you want the least friction from code to a useful trace UI.
Summary
Set tracing env vars (LANGSMITH_TRACING / LANGSMITH_API_KEY or current LangChain equivalents - verify at build), run your compiled graph, open the run in LangSmith, and wrap non-LangChain I/O with traceable or SDK wrappers so custom tools still nest correctly.
Recipe
- Create a LangSmith API key and project (verify UI steps at build).
- Export env vars in every runtime (local, CI, prod workers):
LANGSMITH_TRACING=true(orLANGCHAIN_TRACING_V2=true- confirm current preferred names at build)LANGSMITH_API_KEY=.../LANGCHAIN_API_KEY=...- optional project, workspace, and regional endpoint vars
- Prefer LangChain chat models and tools inside nodes for automatic nesting.
- Wrap raw OpenAI/other clients and decorate pure Python tools with
@traceablewhen needed. - Invoke or stream the graph with a meaningful
thread_idand metadata tags. - In LangSmith, inspect the tree, messages, token usage, and errors per node.
- Pull bad traces into datasets for regression evals.
- Redact secrets; never put live credentials in prompts or tool args that will be traced.
Working Example
import os
from typing import Literal
from langchain.messages import HumanMessage
from langchain_openai import ChatOpenAI # or another provider package
from langchain.tools import tool
from langgraph.graph import StateGraph, MessagesState, START, END
from langgraph.prebuilt import ToolNode
# Required outside the snippet (names evolve - verify at build):
# export LANGSMITH_TRACING=true
# export LANGSMITH_API_KEY=...
# export OPENAI_API_KEY=...
@tool
def search(query: str) -> str:
"""Demo web search tool."""
if "sf" in query.lower():
return "60F and foggy"
return "90F and sunny"
tools = [search]
tool_node = ToolNode(tools)
model = ChatOpenAI(model="gpt-4o-mini").bind_tools(tools) # verify model id at build
def call_model(state: MessagesState):
response = model.invoke(state["messages"])
return {"messages": [response]}
def should_continue(state: MessagesState) -> Literal["tools", "__end__"]:
last = state["messages"][-1]
if getattr(last, "tool_calls", None):
return "tools"
return "__end__"
workflow = StateGraph(MessagesState)
workflow.add_node("agent", call_model)
workflow.add_node("tools", tool_node)
workflow.add_edge(START, "agent")
workflow.add_conditional_edges("agent", should_continue, {"tools": "tools", "__end__": END})
workflow.add_edge("tools", "agent")
app = workflow.compile()
final = app.invoke(
{"messages": [HumanMessage(content="weather in sf?")]},
config={"configurable": {"thread_id": "obs-demo-1"}},
)
print(final["messages"][-1].content)
# Open LangSmith UI -> find the trace for this runWithout LangChain models, keep the graph and wrap the SDK:
from langsmith import traceable
from langsmith.wrappers import wrap_openai
import openai
client = wrap_openai(openai.Client())
@traceable(run_type="tool", name="Search Tool")
def search(query: str) -> str:
return "demo"Deep Dive
What good LangGraph traces show
- Order of nodes and conditional branches taken
- Model messages and tool calls with arguments
- Latency and error stacks per span
- Correlation across a
thread_idfor multi-turn agents
Use a tree/details view for structure and a messages view for conversation-shaped review (UI labels evolve - verify at build).
Metadata and tagging
Attach tags and metadata via runnable config so you can filter prod vs staging, tenant, agent version, or canary cohort.
Stable thread_id values make "show me this user's last failed run" possible.
Avoid bare user ids alone when concurrent sessions exist; add a session suffix.
Pairing with checkpoints
Traces explain why. Checkpoints recover where.
On incidents, open the LangSmith trace first, then load graph state for the thread if you need to resume or re-run from a safe point.
Evals and datasets
Pull failing traces into a dataset. Re-run offline evals when you change prompts, routers, or models so path mix and tool-error rates stay visible.
Privacy and retention
Agents dump CRM fields and tokens into tool observations. Configure masking, limit who can open production projects, and align retention with security policy.
When LangSmith is the right default
Choose LangSmith when:
- Your stack is LangChain/LangGraph-heavy
- You want node nesting with minimal custom instrumentation
- You will use the same platform for datasets and evals
Choose something else when you need strict open-source self-hosting by default, multi-framework neutrality first, or deep eval-first workflows (see Langfuse and Phoenix pages).
Gotchas
- Tracing env not set in workers - local works, prod is blind.
- Wrong regional endpoint - auth fails silently from the app's perspective.
- Unwrapped custom HTTP - tools look like black boxes.
- Huge binary payloads in state - traces and checkpoints bloat; store references.
- Thread id = user id only - collisions across concurrent sessions.
- Secrets in prompts - they will appear in traces; inject via secure config.
- Assuming LangSmith replaces metrics - still need latency/error/cost SLOs in your APM.
- CI without a dedicated project - noisy traces and accidental prod key use.
Alternatives
| Approach | Strength | Weakness |
|---|---|---|
| LangSmith native | Deep LangGraph nesting | SaaS dependency / deployment constraints |
| Langfuse / OTEL stacks | Open standards, self-host options | More wiring for graph semantics |
| Arize Phoenix | Strong eval primitives | Different mental model than LangGraph-first teams |
| Custom structured logs | Full control | Rebuild UI and join logic |
| Provider dashboards only | Token bills | No graph path visibility |
FAQs
Do I need LangChain to trace LangGraph?
No, but LangChain integrations auto-nest. Custom code needs traceable / wrappers.
LANGSMITH_* vs LANGCHAIN_* env vars?
Both families have been used as the product evolved. Confirm the current preferred names in LangSmith docs at build and set them in all runtimes.
Will stream tokens show up?
Yes when models emit streamed tokens under a traced context. Confirm your stream mode and model integration support.
How do I trace only a fraction of production traffic?
Use sampling/project settings in LangSmith (verify current controls at build) or enable tracing only on canary deployments.
Can I self-host?
Deployment options evolve. Check current LangSmith docs for self-hosted/enterprise if required.
How does this page differ from the LangGraph section's LangSmith article?
This page sits with broader monitoring choices (Langfuse, Phoenix, custom, infra pairing). The LangGraph-focused recipe emphasizes graph wiring detail.
How do interrupts / HITL pauses appear?
Paused runs and resume turns should link on the thread; exact UI chrome changes over time, so confirm with a HITL demo trace.
Should CI enable tracing?
Yes for integration suites with a dedicated project and short retention, so flaky tool paths are inspectable.
What alerts should sit beside LangSmith?
Task success rate, tool error rate, p95 node latency, cost per successful thread, and interrupt wait time.
Can I use LangSmith with OpenRouter or other providers?
Yes when the client is instrumented (LangChain model packages or wrappers). Provider choice does not remove the need for host-side tracing.
Related
- Observability with LangSmith for LangGraph Agents - graph wiring detail
- Agent Observability Basics - data model without a vendor
- Langfuse: OpenTelemetry-Based Tracing for Any Framework - framework-agnostic alternative
- Arize Phoenix for Eval-Rigorous Agent Monitoring - eval-first path
- What Agent Observability Actually Needs to Capture - field checklist
- Agent Observability Best Practices - production habits
Stack versions: Pins from the category manifest (verify at build): OpenRouter (~315+ models, July 2026 pricing/fees); LangGraph 1.0+; CrewAI 1.14+; Microsoft Agent Framework 1.0; Vercel AI SDK 6; Pydantic AI (latest); LlamaIndex (latest); OpenAI Agents SDK (latest + MCP); MCP (Linux Foundation governance); A2A (HTTP+SSE+JSON-RPC 2.0); Solana
@solana/web3.js+@solana/spl-token.