indexbus_platform_obs/
metrics_init.rs1#[cfg(feature = "metrics")]
9use crate::errors::{Error, Result};
10
11#[cfg(feature = "metrics-prometheus")]
12use metrics_exporter_prometheus::PrometheusHandle;
13
14#[cfg(feature = "metrics-prometheus")]
19pub fn init_prometheus_recorder() -> Result<PrometheusHandle> {
20 metrics_exporter_prometheus::PrometheusBuilder::new()
21 .install_recorder()
22 .map_err(|e| Error::MetricsInit(e.to_string()))
23}
24
25#[cfg(all(test, feature = "metrics-prometheus"))]
26mod tests {
27 use super::*;
28
29 #[test]
30 fn init_prometheus_recorder_fails_if_called_twice() {
31 let _ = init_prometheus_recorder().expect("first init");
32 let second = init_prometheus_recorder();
33 assert!(matches!(second, Err(crate::errors::Error::MetricsInit(_))));
34 }
35}