Skip to content

Commit

Permalink
feat: histogram label
Browse files Browse the repository at this point in the history
  • Loading branch information
joske committed Feb 15, 2024
1 parent 6e182c6 commit ecf291e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,17 @@ pub fn histogram<V: Into<f64>>(name: &'static str, value: V) {
let histogram = ::metrics::histogram!(name);
histogram.record(value.into());
}

pub fn histogram_label<V: Into<f64>>(name: &'static str, label_key: &'static str, label_value: String, value: V) {
let labels = vec![::metrics::Label::new(label_key, label_value)];
let metric_key = ::metrics::Key::from_parts(name, labels);
let metadata = {
static METADATA: ::metrics::Metadata<'static> = ::metrics::Metadata::new(
"module::path",
::metrics::Level::INFO,
::core::option::Option::Some("module::path"),
);
&METADATA
};
::metrics::with_recorder(|recorder| recorder.register_histogram(&metric_key, metadata)).record(value.into())
}

0 comments on commit ecf291e

Please sign in to comment.