Tracing Claude Code to LangSmith

LangChain · Beginner ·🧠 Large Language Models ·10mo ago

Key Takeaways

The video demonstrates how to set up tracing from Claude Code to LangSmith by setting environment variables, enabling telemetry, and configuring the OpenTelemetry protocol exporter. This allows users to monitor and log their Claude Code sessions in LangSmith, providing detailed insights into model usage, token counts, and costs.

Full Transcript

Hey there. Today you're going to learn how you can set up tracing from Claude Code to Langmouth by just setting a few environment variables. Let's dive right in. First, you're going to need to create a Langmith account and generate an API key. Once you have an account, navigate to your settings page and create a personal access token. This is the only key that we need to connect Claude Code to Langmith. Let's copy this and we'll use it in a second. Claude Code is one of the most impressive and useful AI coding tools to date. I use it every day in my work including on this open deep research agent which I have open here. What's nice is that cloud code can emit open telemetry standard events for monitoring and observability. Langmith can then collect and display these events to give you a full detailed log on everything that happens during your cloud code sessions. To set up tracing to Langmith, all we need to do is set a few environment variables to configure the hotel export from cloud code. The first environment variable that we're going to set is cloud code enable telemetry equal to 1. This basically turns on telemetry for cloud code. Next, we'll specify hotel logs exporter equals OTLP. This specifies the output format to use open telemetry protocol. We'll also specify that the log should be sent with HTTP transport and JSON encoding. This is the format that Linksmith ingestion was built to accept. Now, this is the key piece. If you're using Langsmith Cloud like I just showed, this is the endpoint that you'll specify for logs from Cloud Code. If you're using a self-hosted instance of Langmith, your URL will look a little bit different. You can refer to the docs in the description to go get your URL. Now, we're going to take that API key that we generated earlier and set that in our headers. This is going to allow us to authenticate and connect to Langmith. We'll also specify a tracing project. This will specify where our cloud code traces show up in Langmith so we can find them easily. Finally, we want to enable logging of user prompts and inputs. So, we'll set this variable to true. That's it. All we needed to do was set these six environment variables. Claude Code is now emitting events that are captured and displayed in Linksmith. Now, let's see it in action. Let's go ahead and start a Claude Code session. I'm going to ask Claude Code to broadly describe to me what Open Deep Research does and how it works. We can see that Claude Code is reading quite a few files. This will take a while, so I'm going to skip ahead to when the answer has been generated. We can see that this response is pretty helpful. Let's see what we traced in Langmith. We can see a new trace here in Langmith named Claude Code. If I click into it, I can see each of the individual things that Claude Code did. I've logged the question that was asked initially. We can also see the model names, token usage, and latency from the model requests that claude code makes. Cloud code also sends up costs associated with each request. And we can also see all of the operations that claude code undertakes, like reading files. Now, let's ask a follow-up. We're going to ask Claude Code to write a cloud.md file for this repo. We can see that in this case it comes up with a to-do list and asks us to execute a few commands. We'll play along with it here and go with it. Now let's check back in on our trace in Langmith. In that same trace, we can see that we now have more runs which correspond to the different actions that Claude Code took. One thing to note here is that while we can see the user prompts that we input, we don't have access to the actual system prompts and messages that Claude Code sends to the anthropic models. We also can't see the raw model outputs that come back. This information isn't exported by Enthropics hotel logging. However, we do get token count and cost measurements. We can actually see that after the second question, the total token count and cost for this trace has gone up. This is because each cla code trace is tied to a session. In other words, everything that I do in this session of cloud code is going to get logged to this trace. The waterfall view is particularly interesting. We can already see groups of runs based on timestamp for our first user prompt asking about a repo and then our second user prompt asking cloud code to write a file. Tracing cloud code to linksmith can also be really useful for organizations trying to monitor general usage. API usage for cloud code can easily match or exceed that of a production application. Langmith has these pre-built dashboards to help us see the total number of traces over time in any tracing project, as well as stay on top of any patterns in token usage or costs. To recap, you can set up tracing from Cloud Code to Linksmith just by setting a few environment variables. I've linked a doc in the description with written instructions and those exact variables spelled out. Thanks for watching.

Original Description

You can now trace your claude code sessions to LangSmith! See how to set up tracing from claude code to LangSmith in just a few minutes. Check out the docs for detailed instructions: https://docs.smith.langchain.com/observability/how_to_guides/claude_code
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from LangChain · LangChain · 0 of 60

← Previous Next →
1 Chat With Your Documents Using LangChain + JavaScript
Chat With Your Documents Using LangChain + JavaScript
LangChain
2 LangChain SQL Webinar
LangChain SQL Webinar
LangChain
3 LangChain "OpenAI functions" Webinar
LangChain "OpenAI functions" Webinar
LangChain
4 LangSmith Launch
LangSmith Launch
LangChain
5 LangChain x Pinecone: Supercharging Llama-2 with RAG
LangChain x Pinecone: Supercharging Llama-2 with RAG
LangChain
6 LangChain Expression Language
LangChain Expression Language
LangChain
7 Building LLM applications with LangChain with Lance
Building LLM applications with LangChain with Lance
LangChain
8 Benchmarking Question/Answering Over CSV Data
Benchmarking Question/Answering Over CSV Data
LangChain
9 LangChain "RAG Evaluation" Webinar
LangChain "RAG Evaluation" Webinar
LangChain
10 Fine-tuning in Your Voice Webinar
Fine-tuning in Your Voice Webinar
LangChain
11 Tabular Data Retrieval
Tabular Data Retrieval
LangChain
12 Building an LLM Application with Audio by AssemblyAI
Building an LLM Application with Audio by AssemblyAI
LangChain
13 Superagent Deepdive Webinar
Superagent Deepdive Webinar
LangChain
14 Lessons from Deploying LLMs with LangSmith
Lessons from Deploying LLMs with LangSmith
LangChain
15 Shortwave Assistant Deepdive Webinar
Shortwave Assistant Deepdive Webinar
LangChain
16 Cognitive Architectures for Language Agents
Cognitive Architectures for Language Agents
LangChain
17 Effectively Building with LLMs in the Browser with Jacob
Effectively Building with LLMs in the Browser with Jacob
LangChain
18 Data Privacy for LLMs
Data Privacy for LLMs
LangChain
19 "Theory of Mind" Webinar with Plastic Labs
"Theory of Mind" Webinar with Plastic Labs
LangChain
20 LangChain Templates
LangChain Templates
LangChain
21 Using Natural Language to Query Postgres with Jacob
Using Natural Language to Query Postgres with Jacob
LangChain
22 Building a Research Assistant from Scratch
Building a Research Assistant from Scratch
LangChain
23 Benchmarking RAG over LangChain Docs
Benchmarking RAG over LangChain Docs
LangChain
24 Skeleton-of-Thought: Building a New Template from Scratch
Skeleton-of-Thought: Building a New Template from Scratch
LangChain
25 Benchmarking Methods for Semi-Structured RAG
Benchmarking Methods for Semi-Structured RAG
LangChain
26 LangSmith Highlights: Getting Started
LangSmith Highlights: Getting Started
LangChain
27 LangSmith Highlights: Debugging
LangSmith Highlights: Debugging
LangChain
28 LangSmith Highlights: Datasets
LangSmith Highlights: Datasets
LangChain
29 LangSmith Highlights: Evaluation
LangSmith Highlights: Evaluation
LangChain
30 LangSmith Highlights: Human Annotation
LangSmith Highlights: Human Annotation
LangChain
31 LangSmith Highlights: Monitoring
LangSmith Highlights: Monitoring
LangChain
32 LangSmith Highlights: Hub
LangSmith Highlights: Hub
LangChain
33 SQL Research Assistant
SQL Research Assistant
LangChain
34 Getting Started with Multi-Modal LLMs
Getting Started with Multi-Modal LLMs
LangChain
35 Build a Full Stack RAG App With TypeScript
Build a Full Stack RAG App With TypeScript
LangChain
36 Auto-Prompt Builder (with Hosted LangServe)
Auto-Prompt Builder (with Hosted LangServe)
LangChain
37 LangChain v0.1.0 Launch: Introduction
LangChain v0.1.0 Launch: Introduction
LangChain
38 LangChain v0.1.0 Launch: Observability
LangChain v0.1.0 Launch: Observability
LangChain
39 LangChain v0.1.0 Launch: Integrations
LangChain v0.1.0 Launch: Integrations
LangChain
40 LangChain v0.1.0 Launch: Composability
LangChain v0.1.0 Launch: Composability
LangChain
41 LangChain v0.1.0 Launch: Streaming
LangChain v0.1.0 Launch: Streaming
LangChain
42 LangChain v0.1.0 Launch: Output Parsing
LangChain v0.1.0 Launch: Output Parsing
LangChain
43 LangChain v0.1.0 Launch: Retrieval
LangChain v0.1.0 Launch: Retrieval
LangChain
44 LangChain v0.1.0 Launch: Agents
LangChain v0.1.0 Launch: Agents
LangChain
45 Build and Deploy a RAG app with Pinecone Serverless
Build and Deploy a RAG app with Pinecone Serverless
LangChain
46 Hosted LangServe + LangChain Templates
Hosted LangServe + LangChain Templates
LangChain
47 LangGraph: Intro
LangGraph: Intro
LangChain
48 LangGraph: Agent Executor
LangGraph: Agent Executor
LangChain
49 LangGraph: Chat Agent Executor
LangGraph: Chat Agent Executor
LangChain
50 LangGraph: Human-in-the-Loop
LangGraph: Human-in-the-Loop
LangChain
51 LangGraph: Dynamically Returning a Tool Output Directly
LangGraph: Dynamically Returning a Tool Output Directly
LangChain
52 LangGraph: Respond in a Specific Format
LangGraph: Respond in a Specific Format
LangChain
53 LangGraph: Managing Agent Steps
LangGraph: Managing Agent Steps
LangChain
54 LangGraph: Force-Calling a Tool
LangGraph: Force-Calling a Tool
LangChain
55 LangGraph: Multi-Agent Workflows
LangGraph: Multi-Agent Workflows
LangChain
56 Streaming Events: Introducing a new `stream_events` method
Streaming Events: Introducing a new `stream_events` method
LangChain
57 Building a web RAG chatbot: using LangChain, Exa (prev. Metaphor), LangSmith, and Hosted Langserve
Building a web RAG chatbot: using LangChain, Exa (prev. Metaphor), LangSmith, and Hosted Langserve
LangChain
58 OpenGPTs
OpenGPTs
LangChain
59 Open Source RAG with Nomic's New Embedding Model (and ChromaDB and Ollama)
Open Source RAG with Nomic's New Embedding Model (and ChromaDB and Ollama)
LangChain
60 LangGraph: Persistence
LangGraph: Persistence
LangChain

This video teaches how to set up tracing from Claude Code to LangSmith, allowing users to monitor and log their LLM sessions. By following the steps outlined in the video, users can gain valuable insights into model usage, token counts, and costs.

Key Takeaways
  1. Create a LangSmith account and generate an API key
  2. Set environment variables to configure telemetry and OpenTelemetry protocol exporter
  3. Enable logging of user prompts and inputs
  4. Start a Claude Code session and verify tracing in LangSmith
  5. Explore the tracing dashboard in LangSmith to monitor model usage and costs
💡 Tracing LLM sessions can provide valuable insights into model usage, token counts, and costs, helping users optimize their workflows and reduce costs.

Related AI Lessons

The 2026 AI Model Release Race: Every Major LLM Launch You Need to Know
Stay updated on the 2026 AI model release race, including major LLM launches like Claude Sonnet 5 and GPT-5.6, to leverage the latest advancements in AI technology
Dev.to AI
Call GPT, Claude, and Gemini from one API key — a 3-step setup
Access GPT, Claude, and Gemini through one API key with a 3-step setup using Modelishub
Dev.to AI
Your LLM Doesn’t Pick Stocks — It Remembers Them
Discover how LLMs remember stock picks rather than making actual predictions, and why this matters for AI-driven investment strategies
Medium · Machine Learning
Word Representation
Learn how word representation works in NLP and its importance in understanding human language, enabling applications like text classification and language translation
Medium · NLP
Up next
5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
Dave Ebbelaar (LLM Eng)
Watch →