Skip to main content

aranya_runtime/
metrics.rs

1//! Interface for collecting runtime metrics.
2//!
3//! [`Metrics`] provide an API to collect information about operations preformed within the Aranya runtime.
4
5use core::time::Duration;
6
7/// [`Metrics`] provides an interface to push a named [`Metric`] to a collection.
8pub trait Metrics {
9    type Error: core::error::Error + Send + Sync + 'static;
10
11    fn update(&mut self, name: &'static str, metric: Metric) -> Result<(), Self::Error>;
12}
13
14#[derive(Debug, Clone, PartialEq, Eq, Copy)]
15pub enum Metric {
16    Count(u64),
17    Duration(Duration),
18}
19
20#[derive(Debug, thiserror::Error)]
21pub enum MetricError {
22    #[error("metric type is incompatible")]
23    IncorrectType,
24    #[error("metric cannot be found")]
25    UnknownMetric,
26}