Live Mode is missing usage_metadata and telemetry tracing
Describe the bug
When using ADK with Gemini Live API, the usage_metadata field is always None in Event objects, making it impossible to track token usage for cost monitoring and observability. Additionally, telemetry tracing doesn't work properly for live events, with token usage data being lost instead of creating individual spans for each event.
To Reproduce Steps to reproduce the behavior:
- Install
google-adk - Create a voice agent using
gemini-live-2.5-flashmodel:from google.adk.agents import Agent agent = Agent( name="voice_assistant_agent", model="gemini-live-2.5-flash", # or any other live model tools=[some_tool] ) - Run the agent and process live events:
async for event in live_events: print(f"Usage metadata: {event.usage_metadata}") # Always None - CheckOpenTelemetry traces for token usage
- Observe that token usage is not tracked in telemetry spans
Expected behavior
event.usage_metadatashould contain actual token usage data from the Gemini Live API response- Each live event should create a separate OpenTelemetry span with token usage metrics (
gen_ai.usage.input_tokens,gen_ai.usage.output_tokens,gen_ai.usage.total_tokens)
This is not supported yet. Will convert this to a feature request.
This is not supported yet. Will convert this to a feature request.
@hangfei check the PR, the data is there we just need to pass it to the LlmResponse. Also telemetry is a pretty easy fix, check the pr for that as well.
@hangfei Waiting for this to get merged....
token usage is supported here: https://github.com/google/adk-python/commit/6e5c0eb6e0474f5b908eb9df20328e7da85ebed9.
@wukath to see if we need tracing and evaluate the PR.
@emilmilow Thank you for reporting this. I understand the request is currently under review. Please keep me posted if anything else is needed. Thanks for your patience.
Thank you for reporting this issue and for your patience!
Both usage_metadata propagation and OpenTelemetry tracing in Live Mode (run_live) have since been implemented on main:
-
usage_metadataon Live Events:GeminiLlmConnection._to_generate_content_usage_metadataandGeminiLlmConnection.receive(src/google/adk/models/gemini_llm_connection.py) now extractmessage.usage_metadatafrom the Live API stream (mappingresponse_token_countandresponse_tokens_detailstoGenerateContentResponseUsageMetadata) and emit it onLlmResponse.usage_metadata.postprocess_live_flow(src/google/adk/live/_live_llm_flow.py) finalizes and attachesusage_metadataonto the yielded LiveEvent, so you can inspectevent.usage_metadatadirectly when iterating overrunner.run_live(...).
-
OpenTelemetry Tracing in Live Mode:
BaseAgent.run_live(src/google/adk/agents/base_agent.py) records theinvoke_agentspan via_instrumentation.record_agent_invocation.run_live_flow(src/google/adk/live/_live_llm_flow.py) recordssend_dataspans viatrace_send_data.- Live tool invocations (
src/google/adk/flows/llm_flows/tools/_live_caller.py) recordexecute_toolspans.
We are closing this issue as resolved. If you still encounter any missing fields or have additional questions on recent releases, please feel free to reopen this issue!