Skip to content

[Bug]: AgentOps does not aggregate Google ADK Gemini token usage because ADK emits gen_ai.usage.input_tokens/output_tokens but AgentOps expects prompt_tokens/completion_tokensΒ #1418

Description

@KalidasKalimuthu

Contact Details

k.kalidas@gmail.com

πŸ“¦ Package Version

0.4.21

🎞️ Framework Version

google adk

πŸ”Ž Describe the Bug

AgentOps captures ADK Gemini LLM spans and latency correctly, but trace metrics show zero tokens and zero cost. The issue appears to be a token attribute naming mismatch. Google ADK emits token usage as gen_ai.usage.input_tokens and gen_ai.usage.output_tokens, while AgentOps appears to aggregate only gen_ai.usage.prompt_tokens, gen_ai.usage.completion_tokens, and gen_ai.usage.total_tokens. The ADK trace contains valid Gemini usage_metadata and non-zero token attributes, but AgentOps metrics ignore them.

Details:
Agent Framework: google-adk (Version: 2.1.0)
LLM : gemini-2.5-flash-lite
agentops (0.4.21)
Programming Language : Python 3.13

In AgentOps SpanAttributes, token usage constants are defined as:
LLM_USAGE_COMPLETION_TOKENS = "gen_ai.usage.completion_tokens"
LLM_USAGE_PROMPT_TOKENS = "gen_ai.usage.prompt_tokens"
LLM_USAGE_TOTAL_TOKENS = "gen_ai.usage.total_tokens"

But ADK emits:
gen_ai.usage.input_tokens
gen_ai.usage.output_tokens

This creates a mismatch:

ADK emits β†’ gen_ai.usage.input_tokens
AgentOps expects β†’ gen_ai.usage.prompt_tokens
ADK emits β†’ gen_ai.usage.output_tokens
AgentOps expects β†’ gen_ai.usage.completion_tokens

This appears to be why AgentOps trace metrics return zero tokens/cost

Please normalize input_tokens β†’ prompt_tokens, output_tokens β†’ completion_tokens, and compute total_tokens when absent.

adk single invocation.json

🀝 Contribution

  • Yes, I'd be happy to submit a pull request with these changes.
  • I need some guidance on how to contribute.
  • I'd prefer the AgentOps team to handle this update.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions