Why Observability Matters for AI
AI applications are inherently non-deterministic and complex:- Multi-step workflows: Model calls, tool invocations, data retrieval
- Non-deterministic: Same input can produce different outputs
- Expensive: Token costs, latency, rate limits
- Hard to debug: What went wrong in a 10-step agentic workflow?
- Debug failures: See exactly which step failed and why
- Optimize performance: Identify slow model calls or bottlenecks
- Monitor costs: Track token usage across models
- Improve quality: Analyze outputs and refine prompts
Automatic Tracing
Every action in Genkit is automatically traced:- Timing: Start time, duration
- Input/Output: Request and response data
- Metadata: Model name, token usage, cost
- Errors: Stack traces and error messages
- Hierarchy: Parent-child relationships
Developer UI
The Developer UI provides a local dashboard for testing and debugging:Starting the Dev UI
Features
1. Action Browser- Browse all flows, models, prompts, tools
- See input/output schemas
- Read descriptions and metadata
- Run flows with test inputs
- See results in real-time
- Test streaming responses
- Try different configurations
- View execution traces
- Expand/collapse spans
- See timing breakdowns
- Inspect input/output at each step
- Filter by flow, model, or time range
- Edit
.promptfiles - Test with sample inputs
- See rendered output
- Compare variants
- Test models directly
- Compare different models
- Adjust temperature, topK, etc.
- See token usage and cost
OpenTelemetry Integration
Genkit uses OpenTelemetry for all tracing, making it compatible with any observability platform.How It Works
- Creates OpenTelemetry spans for every action
- Exports spans to configured backends
- Includes Genkit-specific attributes (tokens, model, cost)
Production Monitoring
Google Cloud Trace
Integrate with Google Cloud for production tracing:- Cloud Trace: Distributed tracing across services
- Cloud Logging: Structured logs with trace correlation
- Metrics: Token usage, latency, error rates
- Alerts: Set up alerts on errors or slow requests
Firebase
For Firebase projects:- Cloud Trace integration
- Cloud Logging
- Firebase Console integration
Third-Party Observability
Support for popular platforms:- Sentry: Error tracking and performance monitoring
- Datadog: APM, logs, metrics
- Honeycomb: Distributed tracing and observability
- New Relic: Application performance monitoring
- Jaeger: Open-source distributed tracing
- Zipkin: Distributed tracing system
Custom Telemetry
Add custom attributes to traces:Metrics and Token Tracking
Genkit automatically tracks: Token Usage- Input tokens per request
- Output tokens per request
- Total tokens per flow
- Tokens by model
- Model call duration
- Tool execution time
- End-to-end flow time
- Time to first token (TTFT)
- Cost per request
- Cost per model
- Daily/monthly spend
- Failed requests
- Timeout errors
- Rate limit errors
- Model-specific errors
Trace Export Formats
Genkit supports multiple trace export formats: JSONBest Practices
1. Use Meaningful Step Names
Name your steps clearly:2. Add Custom Metadata
Enrich traces with business context:3. Monitor Token Usage
Set up alerts for unexpected token usage:4. Sample in Production
For high-traffic apps, sample traces:5. Use Dev UI for Debugging
Before deploying:- Run flows in Dev UI with test data
- Inspect traces for unexpected behavior
- Verify token usage and latency
- Test error handling
Debugging Common Issues
High Latency
Check trace for:- Slow model calls → Try faster model
- Multiple sequential tool calls → Can any run in parallel?
- Large prompts → Reduce context size
- Network delays → Check model endpoint
High Token Usage
Check trace for:- Long conversation history → Summarize or truncate
- Verbose prompts → Simplify instructions
- Unnecessary tool calls → Refine tool descriptions
- Large tool responses → Return only needed data
Errors
Check trace for:- Stack trace and error message
- Which step failed
- Input that caused the error
- Model-specific error codes (rate limits, etc.)
Example: Monitoring Dashboard
Query traces programmatically:Next Steps
- Learn about Flows - building traceable workflows
- Explore Architecture - how tracing works internally
- See Plugins - telemetry plugin options