Chain Tracing
Learn how to trace LangChain chains and multi-step workflows with Noveum Trace
This guide shows you how to trace LangChain chains and multi-step workflows using Noveum Trace. You'll learn how to monitor chain execution, intermediate steps, and data flow.
🎯 Use Case
Document Processing Chain: A multi-step chain that processes documents through summarization, analysis, and formatting. We'll trace each step to monitor performance and data quality.
🚀 Complete Working Example
Here's a complete, working example you can copy and run:
📋 Prerequisites
Set your environment variables:
🔧 How It Works
1. Chain Structure
The chain processes data through multiple steps:
- Step 1: Document summarization
- Step 2: Theme analysis
- Step 3: Report formatting
2. Automatic Tracing
Each step in the chain is automatically traced:
- Input data for each step
- LLM calls and responses
- Intermediate outputs
- Step execution times
3. Data Flow Visibility
The dashboard shows:
- Complete data flow through the chain
- Intermediate results at each step
- Performance metrics per step
- Error handling and debugging
🎨 Advanced Examples
Manual Trace Control
For advanced use cases, you can manually control trace lifecycle:
Custom Parent Span Relationships
You can explicitly set parent-child relationships between spans using custom names:
Metadata Structure: The metadata parameter supports a noveum configuration object:
Note: When using custom parent relationships, you must manually control trace lifecycle with start_trace()
and end_trace()
.
LangChain Parent ID Support
For LangGraph and complex workflows, you can use LangChain's built-in parent run IDs:
LangGraph Routing Decision Tracking
Track routing decisions in LangGraph workflows as separate spans:
Conditional Chain
🔍 What Gets Traced
The integration automatically captures:
- LLM Calls: Model, prompts, responses, token usage
- Chains: Input/output flow, execution steps
- Agents: Decision-making, tool usage, reasoning
- Tools: Function calls, inputs, outputs
- Retrievers: Queries, document results
- LangGraph Nodes: Graph execution, node transitions
- Routing Decisions: Conditional routing logic and decisions
Routing Decision Attributes
When you emit routing decisions, the following attributes are automatically captured:
routing.source_node
: The node making the routing decisionrouting.target_node
: The destination noderouting.decision
: The routing decision valuerouting.reason
: Human-readable reason for the decisionrouting.confidence
: Confidence score (0.0 to 1.0)routing.state_snapshot
: State at the time of routingrouting.alternatives
: Other possible routing optionsrouting.tool_scores
: Tool selection scores (if applicable)
📊 What You'll See in the Dashboard
After running these examples, check your Noveum dashboard:
Trace View
- Complete chain execution flow
- Step-by-step processing
- Data transformations
- Intermediate results
Span Details
- Individual step execution times
- Input/output data for each step
- LLM call details
- Error information (if any)
Analytics
- Chain performance metrics
- Step-by-step timing analysis
- Data quality insights
- Error patterns and debugging
🔍 Troubleshooting
Common Issues
Chain not executing?
- Check that all steps are properly connected
- Verify input/output data types match
- Ensure callbacks are added to the LLM
Missing intermediate steps?
- Make sure each step in the chain is traced
- Check that RunnablePassthrough is used correctly
- Verify prompt templates are properly formatted
Performance issues?
- Monitor step execution times
- Check for bottlenecks in specific steps
- Consider parallel processing for independent steps
🚀 Next Steps
Now that you've mastered chain tracing, explore these patterns:
- Basic LLM - Simple LLM tracing
💡 Pro Tips
- Use descriptive step names: Make chain steps easy to identify in traces
- Monitor data quality: Check intermediate results for consistency
- Handle errors gracefully: Add error handling to each step
- Optimize performance: Identify and optimize slow steps
- Test edge cases: Ensure your chain handles various input types
Get Early Access to Noveum.ai Platform
Be the first one to get notified when we open Noveum Platform to more users. All users get access to Observability suite for free, early users get free eval jobs and premium support for the first year.