Skip to main content

OpenTelemetry instrumentation for Google ADK

Project description

TraceAI Google ADK Instrumentation

pypi

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 google.adk.agents import Agent
from google.adk.runners import InMemoryRunner
from google.genai import types

from traceai_google_adk import GoogleADKInstrumentor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk import trace as trace_sdk
from opentelemetry.sdk.trace.export import ConsoleSpanExporter, SimpleSpanProcessor
from fi_instrumentation import register
from fi_instrumentation.fi_types import ProjectType

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

traceai_google_adk-0.1.1.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

traceai_google_adk-0.1.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file traceai_google_adk-0.1.1.tar.gz.

File metadata

  • Download URL: traceai_google_adk-0.1.1.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.13.0 Darwin/24.1.0

File hashes

Hashes for traceai_google_adk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 673329821cfee65e1879e48f1cff1756b36c592120024befd85e65da724d9ea3
MD5 344d386b8fd29bf7dabc8f0866994637
BLAKE2b-256 387f2aa29efa9fb44e092baae0c5764c1144b632dbf719275097b254d7fac179

See more details on using hashes here.

File details

Details for the file traceai_google_adk-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for traceai_google_adk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f4cc35cd6efa0b969d08055b7c9ee05c629f7f073ccf65b6e3bed1e9dfb63911
MD5 dc753f70f816f406d9c379734a5e92cc
BLAKE2b-256 2f07222df7815db84ed21a1638c5dd62c8ed7c08fb929c7ab682f0c81ab5f0e4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page