Skip to content

Incorrect mapping in telemetry usage attributes #2105

@tl-nguyen

Description

@tl-nguyen

Incorrect mapping in telemetry usage attributes. The gen_ai.usage.output_tokens was
incorrectly mapped to llm_response.usage_metadata.total_token_count instead of
llm_response.usage_metadata.candidates_token_count, leading to wrong output token counts in
Langfuse integration.

To Reproduce

Steps to reproduce the behavior:

  1. Install ADK with Langfuse integration
  2. Run ADK agents with any LLM model
  3. Open Langfuse dashboard
  4. Check usage details - observe incorrect output token counts

Expected behavior

gen_ai.usage.output_tokens should correctly map to candidates_token_count for accurate
output token tracking in Langfuse.

Screenshots
Image
shows incorrect output token counts in Langfuse usage details due to wrong
attribute mapping.

Desktop (please complete the following information):

  • OS: Linux Ubuntu 22.04
  • Python version: 3.12.3
  • ADK version: 1.7.0

Model Information:

Affects all models integrated with Langfuse

Additional context

Can be fixed by changing the mapping from llm_response.usage_metadata.total_token_count to
llm_response.usage_metadata.candidates_token_count for the gen_ai.usage.output_tokens
attribute in telemetry.py

Metadata

Metadata

Assignees

Labels

tracing[Component] This issue is related to OpenTelemetry tracing

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions