Google ADK Tracing
Instrument LLM calls made using the Google ADK Python SDK
Install
pip install openinference-instrumentation-google-adk google-adk arize-otel
Setup
Set the GOOGLE_API_KEY
environment variable. Refer to Google's ADK documentation for more details on authentication and environment variables.
export GOOGLE_API_KEY=[your_key_here]
Use the register function to connect your application to Arize AX.
from arize.otel import register
tracer_provider = register(
space_id="your-space-id", # in app space settings page
api_key="your-api-key", # in app space settings page
project_name="your-project-name", # name this to whatever you would like
)
# Import the automatic instrumentor from OpenInference
from openinference.instrumentation.google_adk import GoogleADKInstrumentor
# Finish automatic instrumentation
GoogleADKInstrumentor().instrument(tracer_provider=tracer_provider)
Observe
Now that you have tracing setup, all Google ADK SDK requests will be streamed to Arize AX for observability and evaluation.
import asyncio
from google.adk.agents import Agent
from google.adk.runners import InMemoryRunner
from google.genai import types
def get_weather(city: str) -> dict:
"""Retrieves the current weather report for a specified city.
Args:
city (str): The name of the city for which to retrieve the weather report.
Returns:
dict: status and result or error msg.
"""
if city.lower() == "new york":
return {
"status": "success",
"report": (
"The weather in New York is sunny with a temperature of 25 degrees"
" Celsius (77 degrees Fahrenheit)."
),
}
else:
return {
"status": "error",
"error_message": f"Weather information for '{city}' is not available.",
}
agent = Agent(
name="test_agent",
model="gemini-2.0-flash-exp",
description="Agent to answer questions using tools.",
instruction="You must use the available tools to find an answer.",
tools=[get_weather]
)
async def main():
app_name = "test_instrumentation"
user_id = "test_user"
session_id = "test_session"
runner = InMemoryRunner(agent=agent, app_name=app_name)
session_service = runner.session_service
await session_service.create_session(
app_name=app_name,
user_id=user_id,
session_id=session_id
)
async for event in runner.run_async(
user_id=user_id,
session_id=session_id,
new_message=types.Content(role="user", parts=[
types.Part(text="What is the weather in New York?")]
)
):
if event.is_final_response():
print(event.content.parts[0].text.strip())
if __name__ == "__main__":
asyncio.run(main())
Agent Engine Deployment
When using Vertex AI Agent Engine for remote deployment, instrumentation must be configured within the remote agent module, not in the main application code.
For Agent Engine deployment, include the instrumentation packages in your requirements and set up instrumentation in your agent module:
Main Application:
remote_agent = agent_engines.create(
agent_engine=ModuleAgent(module_name="adk_agent", agent_name="app"),
requirements=[
"google-cloud-aiplatform[agent_engines,adk]",
"arize-otel",
"openinference-instrumentation-google-adk",
],
extra_packages=["adk_agent.py"],
env_vars={
"OTEL_LOG_LEVEL": "DEBUG",
"NO_PROXY": "otlp.arize.com",
"OTEL_EXPORTER_OTLP_ENDPOINT": "https://otlp.arize.com/v1",
"OTEL_EXPORTER_OTLP_TIMEOUT": "60000", #Optional, can prevent "context deadline exceeded" errors
},
)
Agent Module (adk_agent.py
):
from arize.otel import register
from openinference.instrumentation.google_adk import GoogleADKInstrumentor
# Configure instrumentation within the remote agent
tracer_provider = register(
api_key="your-arize-api-key",
space_id="your-arize-space-id",
project_name="adk-agent",
)
GoogleADKInstrumentor().instrument(tracer_provider=tracer_provider)
# Your agent code here...
Resources
Google ADK Financial Advisor Tutorial - Complete example using Google ADK with Arize tracing
Last updated
Was this helpful?