feat: add usage span attributes to telemetry (#356)

Merge https://github.com/google/adk-python/pull/1079

Fixes part of #356

Add usage attributes to span.
Note: Since the handling of GenAI event bodies in OpenTelemetry has not yet been determined, I have temporarily added only attributes related to usage.
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/1079 from soundTricker:feature/356-support-more-opentelemetry-semantics 99a9d0352b4bca165baa645440e39ce7199f072b
PiperOrigin-RevId: 774834279
This commit is contained in:
Keisuke Oohashi
2025-06-23 10:28:14 -07:00
committed by Copybara-Service
parent f033e405c1
commit ea69c9093a
2 changed files with 40 additions and 0 deletions
+10
View File
@@ -195,6 +195,16 @@ def trace_call_llm(
llm_response_json,
)
if llm_response.usage_metadata is not None:
span.set_attribute(
'gen_ai.usage.input_tokens',
llm_response.usage_metadata.prompt_token_count,
)
span.set_attribute(
'gen_ai.usage.output_tokens',
llm_response.usage_metadata.total_token_count,
)
def trace_send_data(
invocation_context: InvocationContext,