|
|
ADK Agent Observability with OpenTelemetry
Author: Venkata Sudhakar
When ADK agents call tools, invoke sub-agents, and interact with external APIs, failures are hard to debug without distributed tracing. OpenTelemetry provides vendor-neutral instrumentation that creates traces spanning the full agent lifecycle. ShopMax India uses this to diagnose latency spikes and tool failures in their multi-agent order processing pipeline. You instrument your code by creating a tracer, wrapping key operations in spans, and exporting traces to Cloud Trace. Each agent turn, tool call, and external API request becomes a traceable span with timing and metadata. The full trace shows exactly where time was spent and where errors occurred. The below example shows how ShopMax India adds OpenTelemetry tracing to their ADK agent tools and runners.
Running the agent with traced tools and logging spans,
It gives the following output,
The price of Sony WH-1000XM5 is Rs 29,990.
Traces exported to Cloud Trace
# In Cloud Trace console:
Trace: agent.turn (total: 1.24s)
|-- gemini.generate_content (0.89s)
|-- tool.get_product_price (0.05s)
product_id: SONY-WH1000XM5
price: 29990
For multi-agent workflows at ShopMax India, propagate the trace context between agents using W3C TraceContext headers. This creates a single trace spanning the orchestrator agent, all sub-agents, and every tool call - making it easy to identify which agent in a 5-step pipeline caused a 3-second delay.
|
|