logfire icon indicating copy to clipboard operation
logfire copied to clipboard

Support Google agents ADK tracing

Open adiberk opened this issue 5 months ago • 5 comments

Description

Do you support agents adk for tracing? If not, is it possible to add support?

adiberk avatar Jun 26 '25 20:06 adiberk

Yes: https://logfire.pydantic.dev/docs/integrations/llms/openai/#openai-agents

Do you think this needs to be more discoverable in the docs somehow?

alexmojaki avatar Jun 26 '25 20:06 alexmojaki

Yes: https://logfire.pydantic.dev/docs/integrations/llms/openai/#openai-agents

Do you think this needs to be more discoverable in the docs somehow?

Sorry I mean the Google agents ADK

adiberk avatar Jun 26 '25 23:06 adiberk

Ah, sorry, didn't even notice it said ADK instead of SDK

alexmojaki avatar Jun 27 '25 09:06 alexmojaki

The ADK comes with built in OpenTelemetry tracing. Therefore all you need is to call logfire.configure(). Here's some sample code to demo it working:

import asyncio

from google.adk import Agent, Runner
from google.adk.sessions import InMemorySessionService
from google.genai import types

import logfire

logfire.configure()


# 1. ‘say_hello’ tool
def say_hello():
    return {'greeting': 'Hello 👋'}


agent = Agent(
    name='hello_agent',
    model='gemini-2.0-flash',
    instruction='Always greet using the say_hello tool.',
    tools=[say_hello],
)

# 2. session service + runner
session_service = InMemorySessionService()

APP_NAME = 'hello_app'
USER_ID = 'demo-user'
SESSION_ID = 'demo-session'  # any string; UUIDs work too

# create the session once


async def main():
    await session_service.create_session(app_name=APP_NAME, user_id=USER_ID, session_id=SESSION_ID)

    runner = Runner(agent=agent, app_name=APP_NAME, session_service=session_service)

    # 3.  single‑turn run
    user_msg = types.Content(role='user', parts=[types.Part(text='hi')])

    async for event in runner.run_async(user_id=USER_ID, session_id=SESSION_ID, new_message=user_msg):
        if event.is_final_response():
            print(event.content.parts[0].text)


if __name__ == '__main__':
    asyncio.run(main())

But I see that the attributes are not quite in the format needed to be displayed nicely in our UI. We can fix that.

alexmojaki avatar Jun 27 '25 09:06 alexmojaki

Awesome thanks!

adiberk avatar Jun 30 '25 16:06 adiberk