Overview
Koog provides comprehensive observability capabilities to monitor AI agents in production. Track execution flows, measure performance, debug issues, and gain insights into agent behavior using OpenTelemetry, custom tracing, and metrics.OpenTelemetry Integration
Installation
Add the OpenTelemetry feature to your agent (JVM only):Configuration Options
Using Custom SDK
Integrate with existing OpenTelemetry setup:Span Hierarchy
OpenTelemetry creates a hierarchical span structure:Span Types
Agent Spansai.koog.agent.create- Agent creation and configurationai.koog.agent.invoke- Single agent execution run
ai.koog.agent.strategy- Strategy execution (graph, functional, planner)
ai.koog.agent.subgraph.execute- Subgraph executionai.koog.agent.node.execute- Individual node execution
ai.koog.llm.inference- LLM API call with prompt and response
ai.koog.tool.execute- Tool execution with arguments and result
Span Attributes
Spans include rich metadata following OpenTelemetry semantic conventions:Span Events
Important events are recorded within spans:Tracing Feature
Installation
The Tracing feature provides lightweight debugging (all platforms):Trace Output Format
Traces are emitted as JSON events:Custom Trace Processors
Implement custom trace handling:Metrics Collection
Custom Metrics Feature
Create a custom feature for metrics:Prometheus Integration
Logging
Structured Logging
Configure Logging Backend
Monitoring Dashboards
Jaeger Dashboard
View distributed traces in Jaeger:Grafana Dashboard
Create custom dashboards with Prometheus metrics:Best Practices
1. Use Sampling in Production
2. Add Contextual Attributes
3. Monitor Key Metrics
Track these essential metrics:- Request rate (requests/second)
- Error rate (errors/total requests)
- P50, P95, P99 latency
- Token usage per request
- Tool execution frequency
- Agent success rate
4. Set Up Alerts
5. Use Correlation IDs
Debugging in Production
Enable Verbose Mode Temporarily
Query Traces by Attributes
Find specific executions in Jaeger:Performance Impact
OpenTelemetry Overhead
- Sampling (10%): ~2-5% overhead
- Full sampling: ~10-15% overhead
- Verbose mode: Additional 5-10% overhead