LangChain / LangGraph
Instrument your LangChain and LangGraph applications with Laminar
Overview
Laminar automatically instruments LangChain and LangGraph operations by simply initializing Laminar at the beginning of your Python application. This allows you to trace and monitor your LLM chains, agents, and graph-based workflows, providing complete visibility into your AI application’s performance, costs, and behavior without needing to modify your existing LangChain/LangGraph code.
Getting Started
1. Install Laminar and LangChain/LangGraph
You’ll need Laminar, LangChain core, any specific LangChain LLM/tool integrations (e.g., for OpenAI), and LangGraph:
2. Set up environment variables & Initialize Laminar
Store your API keys in a .env
file and initialize Laminar once at the start of your application, before any LangChain or LangGraph code is executed.
To see an example of how to integrate Laminar within a FastAPI application, check out our FastAPI integration guide.
3. Use LangChain and LangGraph as usual
LangChain Example (Simple LLMChain):
LangGraph Example (Simple Graph):
All instrumentable LangChain and LangGraph operations are now automatically traced in Laminar.
Monitoring Your LangChain Usage
After instrumenting your LangChain and LangGraph applications with Laminar, you’ll be able to:
- View detailed traces of each chain, agent step, tool usage, and LLM call.
- Track token usage and cost across different models used within LangChain.
- Monitor latency and performance metrics for individual components and overall workflows.
- Analyze prompt engineering by inspecting inputs/outputs at each step.
- Debug issues with complex chains or graphs by visualizing their execution flow.
Visit your Laminar dashboard to view your LangChain traces and analytics.
Advanced Features
Leverage Laminar’s advanced features to get more out of your LangChain instrumentation:
- Sessions - Group related LangChain executions (e.g., a user conversation).
- Metadata - Add custom context (e.g., user IDs, environment details) to your LangChain traces.
- Trace structure - Create custom spans to instrument parts of your application logic outside of LangChain.
- Realtime Monitoring - Observe your LangChain applications in real-time.