use axum::{extract::State, response::IntoResponse}; use metrics_exporter_prometheus::{PrometheusBuilder, PrometheusHandle}; pub fn init() -> PrometheusHandle { PrometheusBuilder::new().install_recorder().expect("install prometheus recorder") } pub async fn render(State(handle): State) -> impl IntoResponse { handle.render() } /// A render handle that does NOT install the global recorder — the global is a /// process-wide singleton, so tests (many `AppState`s per process) must not /// call [`init`]. Metrics emitted via the macros are dropped under this handle, /// which is fine for tests that only exercise routes. #[cfg(test)] pub fn test_handle() -> PrometheusHandle { PrometheusBuilder::new().build_recorder().handle() }