AI Hints
Home›LangChain Tutorial›Cost, Logging and Tracing
LangChain · Lesson 87 of 120

Tracing with LangSmith

Seeing every step.

⏱ 2 min read▶ Video at 1:38:43🎓 Free
Watch this lesson in the LangChain courseWatch on YouTube ↗Full LangChain course

Writing your own logs is fine for small apps. But for agents with many steps, you want to see everything. Every prompt, every tool call, every token, laid out as a tree. That's tracing, and LangSmith is LangChain's tracing service.

Tracing with LangSmith
From the video: Tracing with LangSmith
  • Agents have many steps
  • See everything
  • Tracing with LangSmith

Turning on tracing

Tracing needs no code changes. Create a LangSmith account, and an API key. Then set three environment variables. Tracing true, your key, and a project name. Every chain and agent run is now sent to LangSmith, automatically.

.envpython
# .env
LANGSMITH_TRACING=true
LANGSMITH_API_KEY=your-key-here
LANGSMITH_PROJECT=riverside-books

What you see in a trace

In LangSmith, each run is a tree. You see the exact prompt sent to the model, the reply, each tool call with its inputs and outputs, the tokens and cost, and how long every step took. When an agent does something odd, the trace shows you why.

keyvalue
Promptsexactly as sent
Tool callsinputs and outputs
Tokens and costper step
Timingfind slow steps

Summary

LangSmith traces every step of your chains and agents, with just three environment variables. Next, checking whether answers are actually correct.

Key takeaways
  • LANGSMITH_TRACING=true
  • API key, project
  • A tree of every step
Next up: Evaluating Answers — LLM as a judge