pub struct MetricsCallback { /* private fields */ }Expand description
Callback that collects latency, token, and error metrics.
Uses the standard RunEvent lifecycle events to measure model and tool
call latency, accumulate token usage, and count errors.
Call snapshot() at any time to read the
current metrics, or reset() to zero them out.
Implementations§
Source§impl MetricsCallback
impl MetricsCallback
pub fn new() -> Self
Sourcepub async fn snapshot(&self) -> MetricsSnapshot
pub async fn snapshot(&self) -> MetricsSnapshot
Take a snapshot of the current metrics.
Sourcepub async fn record_tokens(&self, input_tokens: u64, output_tokens: u64)
pub async fn record_tokens(&self, input_tokens: u64, output_tokens: u64)
Record token usage externally (e.g. from a ChatResponse).
This allows callers that have access to the actual TokenUsage from
model responses to feed it into the metrics.
Trait Implementations§
Source§impl CallbackHandler for MetricsCallback
impl CallbackHandler for MetricsCallback
Auto Trait Implementations§
impl Freeze for MetricsCallback
impl !RefUnwindSafe for MetricsCallback
impl Send for MetricsCallback
impl Sync for MetricsCallback
impl Unpin for MetricsCallback
impl UnsafeUnpin for MetricsCallback
impl !UnwindSafe for MetricsCallback
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more