Skip to main content

Module usage_tracking

Module usage_tracking 

Source
Expand description

Stream wrapper that records token usage on the active tracing span.

Wraps any LlmResponseStream and intercepts responses carrying UsageMetadata, recording standardized gen_ai.usage.* fields via adk_telemetry::record_llm_usage.

This is applied once per provider in generate_content, so every model gets consistent telemetry without duplicating recording logic.

Functionsยง

with_usage_tracking
Wrap an LlmResponseStream so that the last UsageMetadata seen is recorded on the provided tracing span when the stream yields it.