tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Generative AI > Google Gemini API > ADK Distributed Tracing with Cloud Trace

ADK Distributed Tracing with Cloud Trace

Author: Venkata Sudhakar

Distributed tracing gives visibility into exactly where time is spent during an ADK agent request - how long the model took to respond, which tools were called, how long each tool took, and where errors occurred. ShopMax India uses Cloud Trace with OpenTelemetry to build a complete picture of every agent interaction, from the HTTP request entry point through model calls and downstream tool invocations.

OpenTelemetry (OTel) is the industry standard for instrumentation. The opentelemetry-sdk-python package integrates with Cloud Trace via the google-cloud-trace exporter. Each logical unit of work becomes a span - the agent handler creates a root span, and each tool call creates a child span. Trace IDs are propagated in HTTP headers so spans across services are linked into a single trace in the Cloud Trace console.

The below example shows an ADK agent with full OpenTelemetry tracing instrumented across the request handler and tool calls.


It gives the following output,

Reply: Your order ORD-5042 has been shipped and is expected to arrive by 8 April 2026.
Trace exported to Cloud Trace.

# Cloud Trace console shows:
# agent.request                          1,842 ms (root span)
#   tool.check_order_status                 52 ms
#   gemini.generate_content              1,780 ms

In production, propagate the W3C trace context header (traceparent) from the incoming HTTP request into the root span so that traces link across services - the API gateway, the ADK agent, and any downstream microservices all appear as a single trace. Create Cloud Trace latency distributions in Cloud Monitoring to alert when the p99 agent response time exceeds 5 seconds, giving the ShopMax on-call team early warning before customers notice degraded performance.


 
  


  
bl  br