Google ADK (tracing)

Google Agent Development Kit (ADK) is a framework for building agents with tools and multi-agent workflows. Respan captures ADK runner, agent, LLM, and tool spans, then exports them through the Respan tracing pipeline.

This tracing setup uses your Google model credentials directly through ADK. To route model calls through Respan instead, use the Google ADK gateway setup.

Create an account at platform.respan.ai and grab an API key.

Run npx @respan/cli setup to set up with your coding agent.

See Google ADK gateway setup to route model calls through the Respan gateway.

Setup

1

Install packages

$pip install respan-ai respan-instrumentation-google-adk "google-adk[extensions]"
2

Set environment variables

$export GOOGLE_API_KEY="YOUR_GOOGLE_API_KEY"
$export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"

GOOGLE_API_KEY is used by ADK for direct model requests. RESPAN_API_KEY exports traces to Respan.

3

Initialize and run

1import asyncio
2
3from google.adk.agents import Agent
4from google.adk.runners import Runner
5from google.adk.sessions import InMemorySessionService
6from google.genai import types
7from respan import Respan
8from respan_instrumentation_google_adk import GoogleADKInstrumentor
9
10respan = Respan(instrumentations=[GoogleADKInstrumentor()])
11
12agent = Agent(
13 name="assistant",
14 model="gemini-2.0-flash",
15 instruction="You are a concise assistant.",
16)
17
18async def main():
19 session_service = InMemorySessionService()
20 session = await session_service.create_session(
21 app_name="google-adk-demo",
22 user_id="user_1",
23 )
24 runner = Runner(
25 agent=agent,
26 app_name="google-adk-demo",
27 session_service=session_service,
28 )
29 message = types.Content(
30 role="user",
31 parts=[types.Part(text="Say hello in one sentence.")],
32 )
33
34 async for event in runner.run_async(
35 user_id="user_1",
36 session_id=session.id,
37 new_message=message,
38 ):
39 if event.is_final_response():
40 print(event.content.parts[0].text)
41
42 respan.flush()
43 respan.shutdown()
44
45asyncio.run(main())
4

View your trace

Open the Traces page to see ADK runner, agent, model, and tool spans.

Configuration

ParameterTypeDefaultDescription
api_key / apiKeystr | None / string | undefinedRESPAN_API_KEYRespan API key used to export traces.
base_url / baseURLstr | None / string | undefinedRESPAN_BASE_URLOptional Respan trace export API URL.
instrumentationslist / RespanInstrumentation[][]Include GoogleADKInstrumentor() or new GoogleADKInstrumentor() to activate Google ADK tracing.

Attributes

In Respan()

Set defaults at initialization. These apply to all spans from the instrumented ADK run.

1from respan import Respan
2from respan_instrumentation_google_adk import GoogleADKInstrumentor
3
4respan = Respan(
5 instrumentations=[GoogleADKInstrumentor()],
6 customer_identifier="user_123",
7 metadata={"service": "adk-api", "version": "1.0.0"},
8)

With propagate_attributes

Override per-request attributes using a context scope.

1from respan import Respan, propagate_attributes
2from respan_instrumentation_google_adk import GoogleADKInstrumentor
3
4respan = Respan(instrumentations=[GoogleADKInstrumentor()])
5
6async def handle_request(user_id: str, message: str):
7 with propagate_attributes(
8 customer_identifier=user_id,
9 thread_identifier="conv_abc_123",
10 metadata={"plan": "pro"},
11 ):
12 output = await run_agent_once(message)
13 return output
AttributeTypeDescription
customer_identifierstr / stringIdentifies the end user in Respan analytics.
thread_identifierstr / stringGroups related messages into a conversation.
metadatadict / Record<string, unknown>Custom key-value pairs.

Captured spans

  • ADK runner invocations as workflow spans
  • Agent invocations as agent spans
  • Model calls as chat spans with prompts, completions, tool definitions, and token fields
  • Tool executions as tool spans with normalized input and output