macro_rules! define_histogram {
($name:ident < $label:ty > = $buckets:expr) => { ... };
}Expand description
Defines a histogram type with compile-time validated bucket boundaries.
This macro creates a newtype wrapper around Histogram<L, N> with specific bucket
boundaries. The bucket values are validated at compile time to ensure they are in
strictly ascending order.
§Syntax
define_histogram!(HistogramName<LabelType> = [bucket1, bucket2, ...]);§Examples
Define a histogram with custom labels:
use aetos::{define_histogram, Label};
#[derive(Label, Hash, Eq, PartialEq, Clone, Debug)]
struct HttpLabel {
method: &'static str,
status: u16,
}
define_histogram!(HttpLatency<HttpLabel> = [0.05, 0.1, 0.5, 1.0, 5.0]);Define an unlabeled histogram:
use aetos::define_histogram;
define_histogram!(ResponseTime<()> = [0.1, 0.5, 1.0]);Invalid bucket ordering fails at compile time:
ⓘ
use aetos::define_histogram;
// This will fail because buckets are not in ascending order
define_histogram!(Bad<()> = [1.0, 0.5, 2.0]);Histogram labels come from the type parameter, not the label attribute:
ⓘ
use aetos::{define_histogram, metrics};
define_histogram!(ResponseTime<()> = [0.1, 0.5, 1.0]);
#[metrics]
struct Metrics {
// This will fail - histograms don't support 'label' attribute
#[histogram(help = "Response time", label = "endpoint")]
response_time: ResponseTime,
}