FromZero2AI
CoursesPlaygroundBlogContact
Support on Ko-fi
AI Observability & Production Monitoring • Module A: Tracing & DebuggingLesson 1: LLM Tracing with LangSmith & Langfuse
Next

Lesson 1: LLM Tracing with LangSmith & Langfuse

Instrument LangChain, LangGraph, and raw SDK calls to produce distributed traces. Use LangSmith and Langfuse to visualize full agent execution trees, token counts, and latency breakdowns.

By Bishwambhar Sen • Last updated October 13, 2026

Built with AI for beginners. Free forever.

Support on Ko-fi•About•Contact•Blog•Privacy Policy•Terms of Service

You can't debug what you can't see. LLM tracing gives you a call-by-call view of what your AI system did: which model was called, with what inputs, what it returned, how many tokens it used, and how long each step took. Without it, production debugging is guesswork.

What a Trace Captures

FieldWhy It Matters
trace_idLinks all spans in one user request — cross-reference with your app logs
modelConfirm the right model is being used, detect unexpected fallbacks
input_tokens / output_tokensCost tracking and budget alerting
latency_msFind the slow step in multi-step chains
inputs / outputsDebug unexpected behavior — see exactly what went in and came out
status (ok / error)Alert on LLM call failures, track error rates over time

Choose Your Tracing Tool

Best for: Best for LangChain/LangGraph applications. Native integration with LCEL chains and LangGraph agents.

# pip install langsmith
import os
os.environ["LANGCHAIN_TRACING_V2"] = "true"
os.environ["LANGCHAIN_API_KEY"] = "ls_..."
os.environ["LANGCHAIN_PROJECT"] = "my-ai-app"

# That's it — all LangChain/LangGraph calls are now traced automatically

from langchain_anthropic import ChatAnthropic
from langchain_core.prompts import ChatPromptTemplate

llm = ChatAnthropic(model="claude-haiku-4-5-20251001")
prompt = ChatPromptTemplate.from_template("Answer: {question}")
chain = prompt | llm

# This call is traced: inputs, outputs, latency, token usage, errors
result = chain.invoke({"question": "What is RAG?"})

# Traces appear in https://smith.langchain.com
# Drill into: each chain step, token counts, cost per run, latency breakdown

Trace from day one.Retrofitting tracing into a production system is painful — every LLM call is buried in business logic. Add it at the start and you'll have baseline latency, cost data, and an error history before you ever need to debug a production incident.

Lesson 2 uses the data from your traces to build a cost tracking and optimization dashboard — turning token usage numbers into actionable cost reduction.