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):Monitoring 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.
Enrich your LangChain traces
- Attach sessions, user IDs, metadata, and tags to LangChain spans via the SDK reference.
- Wrap the functions around your chains and graphs with
observeand mark them as TOOL spans so they show up in the transcript.
Related integrations
deepagents
Trace deepagents runs, subagents, and tool calls.
Pydantic AI
Trace Pydantic AI agent runs and typed tool calls.
LiteLLM
One integration for every model LiteLLM routes to.
OpenAI
Trace the OpenAI SDK directly in TypeScript and Python.
Langfuse
Keep Langfuse and send the same spans to Laminar too.
All integrations
Browse every provider, framework, coding agent, and browser integration Laminar supports.