LangChain Integration
Opik provides seamless integration with LangChain through the opik-langchain
package, allowing you to trace, monitor, and debug your LangChain applications.
Features
- Comprehensive Tracing: Automatically trace LLM calls, chains, tools, retrievers, and agents
- Hierarchical Visualization: View your LangChain execution as a structured trace with parent-child relationships
- Detailed Metadata Capture: Record model names, prompts, completions, usage statistics, and custom metadata
- Error Handling: Capture and visualize errors at every step of your LangChain execution
- Custom Tagging: Add custom tags to organize and filter your traces
Installation
Option 1: Using npm
Option 2: Using yarn
Requirements
- Node.js ≥ 18
- LangChain (
@langchain/core
≥ 0.3.42) - Opik SDK (automatically installed as a dependency)
Basic Usage
Using with LLM Calls
You can add the OpikCallbackHandler in two ways in LangChain: at construction time and at execution time. Here’s how to use both approaches:
Configuring for All Components
You can also set up the handler to be used across all LangChain components in your application:
Advanced Configuration
The OpikCallbackHandler
constructor accepts several options to customize the integration:
Troubleshooting
Missing Traces: Ensure you’re providing the OpikCallbackHandler
to both the component constructor and each invoke call.
Incomplete Hierarchies: For proper parent-child relationships, use the same handler instance throughout your application.
Performance Impact: The Opik integration adds minimal overhead to your LangChain application.