Overview
LangSmith provides specialized observability for LLM applications, complementing OpenTelemetry’s infrastructure monitoring with LLM-specific insights.Dual Observability: This project supports both OpenTelemetry (infrastructure) and LangSmith (LLM-specific) tracing simultaneously.
Why LangSmith?
LangSmith gives you superpowers for debugging and optimizing LLM applications:Trace Every LLM Call
See exact prompts, completions, and intermediate steps
Prompt Engineering
Iterate on prompts using real production data
Create Datasets
Build test datasets from production traces
Compare Models
Run evaluations to compare model performance
Track Costs
Monitor LLM API costs per user and session
Collect Feedback
Gather user ratings and analyze trends
Quick Start
1. Create LangSmith Account
1
Sign Up
Visit smith.langchain.com and create a free account
2
Create Project
Create a new project (e.g., “mcp-server-langgraph”)
3
Get API Key
Go to Settings → API Keys → Create API Key
2. Configure Environment
Add to your.env file:
3. Start Tracing
That’s it! All agent invocations are now automatically traced:4. View Traces
Visit smith.langchain.com to see your traces in real-time!What’s Captured
Every trace includes:LLM Calls
LLM Calls
- Full prompts sent to LLM
- Complete model responses
- Token counts (input/output)
- Model parameters (temperature, max_tokens)
- Latency breakdown
Agent Steps
Agent Steps
- Routing decisions
- Tool invocations
- Intermediate states
- Conditional logic flows
Metadata
Metadata
- User ID and session ID
- Request source
- Environment (dev/staging/prod)
- Custom tags
Errors
Errors
- Full Python stack traces
- Input that caused error
- Error context and timing
Adding Custom Metadata
Enrich traces with business context:- User tier: Find all premium user interactions
- Department: Analyze usage by cost center
- Priority: Debug high-priority requests first
Datasets and Evaluation
Create Dataset from Traces
1
Filter Traces
In LangSmith UI, filter for successful traces from the last week
2
Select Examples
Click “Add to Dataset” and select representative examples
3
Name Dataset
Save as “prod-examples-2025-01”
Run Evaluations
Compare model performance:- Latency comparison: Which model is faster?
- Cost analysis: Which is more cost-effective?
- Quality metrics: Custom evaluators for accuracy
Collecting User Feedback
Capture user ratings on responses:Debugging with LangSmith
Find Failing Traces
1
Filter by Status
In LangSmith UI, filter:
status:error2
Sort by Time
Sort by timestamp descending to see recent failures
3
Analyze
Click on trace to see full error context:
- Exact input that caused failure
- Full Python stack trace
- All intermediate steps before error
- Timing information
Optimize Slow Traces
Find performance bottlenecks:- Filter:
latency > 5s - Sort: By latency descending
- Expand trace: See timing breakdown
- Identify bottleneck:
- Slow LLM calls → Try faster model
- Slow tool calls → Add caching
- Redundant calls → Optimize logic
Compare Traces
Compare successful vs. failed traces side-by-side:1
Select Two Traces
Shift+click to select two traces
2
Click Compare
See side-by-side diff of inputs, steps, outputs
3
Identify Differences
Find what caused different outcomes
Best Practices
Project Organization
Project Organization
Create separate projects for each environment:
my-agent-dev- Developmentmy-agent-staging- Stagingmy-agent-prod- Production
Tagging Strategy
Tagging Strategy
Use consistent, searchable tags:
- Environment:
production,staging,development - User tier:
free,pro,enterprise - Feature:
chat,analysis,search - Priority:
high,medium,low
Cost Monitoring
Cost Monitoring
Track costs in LangSmith:
- Go to project → Analytics
- View “Cost Over Time” chart
- Set budget alerts
- Identify high-cost users/features
Sampling (High Volume)
Sampling (High Volume)
For very high traffic, sample traces:
Privacy Compliance
Privacy Compliance
Redact sensitive data before logging:
Integration with OpenTelemetry
This project supports both observability systems simultaneously:| Feature | OpenTelemetry | LangSmith |
|---|---|---|
| Infrastructure Metrics | ✅ CPU, memory, network | ❌ |
| Distributed Tracing | ✅ Service-to-service | ⚠️ Limited |
| LLM Call Tracing | ⚠️ Basic | ✅ Full details |
| Prompt Engineering | ❌ | ✅ |
| Model Evaluation | ❌ | ✅ |
| Cost Tracking | ❌ | ✅ |
| User Feedback | ❌ | ✅ |
Best of both worlds: Use OpenTelemetry for infrastructure monitoring and LangSmith for LLM-specific insights.
Example Code
See complete examples in the repository:Resources
LangSmith Docs
Official LangSmith documentation
Observability Guide
Dual observability setup
API Reference
LangSmith API reference
Example Code
Complete code examples
Ready to trace? Just set
LANGSMITH_TRACING=true in your .env and all agent invocations will be automatically traced!