pub struct MetricsRegistry {
pub requests_total: Counter,
pub requests_success: Counter,
pub requests_error: Counter,
pub tokens_input: Counter,
pub tokens_output: Counter,
pub cache_read_tokens: Counter,
pub cache_creation_tokens: Counter,
pub tool_calls_total: Counter,
pub tool_errors: Counter,
pub active_sessions: Gauge,
pub request_latency_ms: Histogram,
pub cost_total_micros: Counter,
/* private fields */
}Expand description
Agent-specific metrics registry.
Tracks metrics locally with atomic counters, and optionally exports
to OpenTelemetry when the otel feature is enabled.
Fields§
§requests_total: Counter§requests_success: Counter§requests_error: Counter§tokens_input: Counter§tokens_output: Counter§cache_read_tokens: Counter§cache_creation_tokens: Counter§tool_calls_total: Counter§tool_errors: Counter§active_sessions: Gauge§request_latency_ms: Histogram§cost_total_micros: CounterImplementations§
Source§impl MetricsRegistry
impl MetricsRegistry
pub fn new(_config: &MetricsConfig) -> Self
pub fn with_otel(_config: &MetricsConfig, otel_config: &OtelConfig) -> Self
Available on crate feature
otel only.pub fn record_request_start(&self)
pub fn record_request_end(&self, success: bool, latency_ms: f64)
pub fn record_tokens(&self, input: u32, output: u32)
pub fn record_cache(&self, read: u32, creation: u32)
pub fn record_tool_call(&self, success: bool)
pub fn record_cost(&self, cost_usd: f64)
pub fn total_cost_usd(&self) -> f64
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for MetricsRegistry
impl !RefUnwindSafe for MetricsRegistry
impl Send for MetricsRegistry
impl Sync for MetricsRegistry
impl Unpin for MetricsRegistry
impl !UnwindSafe for MetricsRegistry
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
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.