pub fn record_llm_usage(usage: &LlmUsage)Available on crate feature
telemetry only.Expand description
Record LLM token usage on the current span.
Call this after receiving the final LlmResponse to populate the
gen_ai.usage.* fields declared by llm_generate_span.
Fields are only recorded when present (non-zero / Some). This is safe to call
even if the current span was not created by llm_generate_span — unknown
fields are silently ignored by tracing.
§Example
use adk_telemetry::{LlmUsage, record_llm_usage};
let usage = LlmUsage {
input_tokens: 100,
output_tokens: 50,
total_tokens: 150,
cache_read_tokens: Some(80),
..Default::default()
};
record_llm_usage(&usage);