Trace-Based Debugging
Genkit automatically collects detailed execution traces that show every step of your flow execution.Enabling Traces
Traces are automatically collected when:-
Using
genkit start: -
Running with
GENKIT_ENV=dev: -
Executing flows via CLI:
Viewing Traces in Developer UI
The Developer UI provides the most powerful trace inspection:-
Start the Developer UI:
-
Navigate to Traces section at
http://localhost:4000 -
Select a trace to inspect:
- Recent executions appear at the top
- Failed executions are highlighted
- Click any trace to view details
Trace Information
Each trace includes:- Span Tree: Hierarchical view of all operations
- Timing Data: Duration of each step
- Input/Output: Data passed between steps
- Model Interactions: Prompts sent and responses received
- Error Details: Stack traces and error messages
- Metadata: Flow name, version, labels, and attributes
Debugging Common Issues
Flow Execution Failures
Symptom: Flow throws an error or returns unexpected results Debug Steps:-
Check the trace in the Developer UI:
- Identify which step failed
- Review error message and stack trace
- Examine input data to that step
-
Run the flow with test data:
-
Verify input schema:
-
Check each step:
- Review the trace to see where execution stopped
- Check if null or undefined values are passed
- Verify model responses are as expected
Model Response Issues
Symptom: Model returns unexpected or low-quality responses Debug Steps:-
Inspect the prompt in traces:
- View the exact prompt sent to the model
- Check if template variables were substituted correctly
- Verify context and examples are included
-
Test prompt directly in Developer UI:
- Navigate to Prompts section
- Select your prompt
- Try different inputs
- Compare outputs from different models
-
Add prompt logging:
-
Check model configuration:
Streaming Issues
Symptom: Streaming output doesn’t work or is incomplete Debug Steps:-
Test streaming with CLI:
-
Verify streaming implementation:
-
Check for blocking operations:
- Ensure you’re not awaiting the full response before streaming
- Verify no synchronous operations block the event loop
Performance Issues
Symptom: Flows are slow or timeout Debug Steps:-
Analyze timing in traces:
- Open the trace in Developer UI
- Identify the slowest spans
- Check if model calls are taking too long
-
Measure specific operations:
-
Check for unnecessary operations:
- Review trace to find redundant model calls
- Look for sequential operations that could be parallel
- Verify retrieval queries are optimized
-
Optimize model configuration:
Context and RAG Issues
Symptom: Model doesn’t use provided context or retrieval fails Debug Steps:-
Verify context is passed:
-
Inspect retrieval in traces:
-
Check document retrieval:
- View retriever span in trace
- Verify documents were found
- Check similarity scores
- Ensure embeddings are generated correctly
Schema Validation Errors
Symptom: Input/output validation fails Debug Steps:-
Add detailed error handling:
-
Test schema directly:
-
Review trace for schema errors:
- Check error message in trace
- Verify actual vs expected types
- Ensure all required fields are provided
Developer UI Debugging Features
Real-Time Trace Inspection
When running withgenkit start, traces appear immediately:
- Run a flow from the Flows section
- Click “View Trace” to inspect execution
- Expand each span to see details
- Review timing to identify bottlenecks
Comparing Executions
Compare multiple executions to identify patterns:- Run the same flow with different inputs
- View traces side-by-side
- Compare model responses
- Identify inconsistencies
Error Highlighting
Failed executions are clearly marked:- Red indicators for errors
- Stack traces in span details
- Error messages at the top level
- Failed step highlighted in span tree
CLI Debugging Commands
Running Flows with Verbose Output
Extracting Debug Data
Extract traces for offline analysis:Batch Testing for Debugging
Test multiple scenarios:Logging Best Practices
Strategic Console Logs
Add logs at key points:Structured Logging
Use JSON for structured logs:Debugging in Production
While you shouldn’t run withGENKIT_ENV=dev in production, you can:
-
Use evaluation datasets to reproduce issues:
-
Test locally with production data:
- Enable production monitoring (see Observability docs)
Tips for Effective Debugging
- Always check traces first - They contain the most complete information
- Use labels to organize debug sessions
- Test incrementally - Debug one component at a time
- Compare working vs broken - Run working examples alongside failing ones
- Save traces - Extract and save traces for complex issues
- Use streaming - Helps identify where generation stops
- Review prompts - Ensure templates render correctly
- Check schemas - Validate input/output types match expectations
Common Debugging Patterns
Isolate the Issue
Binary Search Debugging
Comment out half the flow to find the problematic section:Add Intermediate Outputs
Next Steps
- Explore the Developer UI features in depth
- Learn about Testing strategies
- Review CLI commands for advanced debugging
- Check out Observability for production monitoring