OpenTelemetry instrumentation for Google ADK
Project description
TraceAI Google ADK Instrumentation
Python auto-instrumentation library for Google ADK.
Quickstart
In this example we will instrument a small program that uses Gemini and observe the traces in Future AGI Dashboard
Install packages.
pip install traceai-google-adk
In a python file, set up the GoogleADKInstrumentor and configure the tracer to send traces to Observe.
import asyncio
from fi_instrumentation import register
from fi_instrumentation.fi_types import ProjectType
from google.adk.agents import Agent
from google.adk.runners import InMemoryRunner
from google.genai import types
from traceai_google_adk import GoogleADKInstrumentor
tracer_provider = register(
project_name="test_project",
project_type=ProjectType.OBSERVE,
)
GoogleADKInstrumentor().instrument(tracer_provider=tracer_provider)
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.5-flash-preview-05-20",
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())
Since we are using Gemini, we must set the GOOGLE_API_KEY environment variable to authenticate with the Gemini API.
export GOOGLE_API_KEY=your-api-key
Run the python file to send the traces to Future AGI Platform.
python your_file.py
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file traceai_google_adk-0.1.4.tar.gz.
File metadata
- Download URL: traceai_google_adk-0.1.4.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a46b5ae918e5692544aa9f2ff44974dec982519cdfbf4f2b59ef39b700d6e57
|
|
| MD5 |
40fd5a12f5a95cf6e9c273837ba21932
|
|
| BLAKE2b-256 |
0c46b12255fca3361db2c7bcead0158279ca48ad661dce94788d0779a95ad431
|
File details
Details for the file traceai_google_adk-0.1.4-py3-none-any.whl.
File metadata
- Download URL: traceai_google_adk-0.1.4-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a387e5f09bbc734b3e398dadab540bce3b3bff3d48846e91038687a7ecc7215
|
|
| MD5 |
3de29bbacd43b36d2a32c11a58b49f29
|
|
| BLAKE2b-256 |
ea13282a5999707480fcb8867e72b858bda4eaee981037a5c018ba7dd7739b85
|