fix(google-adk): support ADK 2.1+ input_tokens/output_tokens field names#1420
Open
uttam12331 wants to merge 1 commit into
Open
fix(google-adk): support ADK 2.1+ input_tokens/output_tokens field names#1420uttam12331 wants to merge 1 commit into
uttam12331 wants to merge 1 commit into
Conversation
Google ADK >=2.1 emits input_tokens/output_tokens in usage_metadata instead of prompt_token_count/candidates_token_count, causing token counts to be missing from spans (issue AgentOps-AI#1418). Add elif fallbacks so both old-style and new-style field names are accepted. Also add total_tokens fallback. Old-style fields take priority when both are present for backward compatibility. Adds 11 unit tests covering old-style, new-style, mixed, and missing field scenarios.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Google ADK >=2.1 changed the field names in
usage_metadatafrom:prompt_token_counttoinput_tokenscandidates_token_counttooutput_tokenstotal_token_counttototal_tokensThe existing code in
agentops/instrumentation/agentic/google_adk/patch.pyonly checked for the old field names, so Gemini token counts via ADK 2.1+ were silently dropped and never recorded in spans.Fixes #1418.
Fix
Added
eliffallbacks in theusage_metadataextraction block to handle both old-style and new-style field names. Old-style fields take priority when both are present for backward compatibility.Tests
Added 11 unit tests in
tests/unit/instrumentation/google_adk/test_token_extraction.pycovering:All 11 new tests pass. Existing test suite: 491 passed, 1 pre-existing unrelated failure.