diff --git a/CHANGELOG.md b/CHANGELOG.md index 80a7d4a..0e546f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file. - +# [0.3.1] - 2023-02-16 + +### Added + +- `with_prefix` to `PrometheusMetricLayerBuilder`, which can be used to rename the default prefix (`axum`) for all metrics. This is especially useful when + working with cargo workspaces that has more than one `axum_prometheus` instance (since environment variables don't work there). + ## [0.3.0] - 2023-01-04 ### Added @@ -46,6 +53,7 @@ All notable changes to this project will be documented in this file. First version. -[unreleased]: https://github.com/Ptrskay3/axum-prometheus/compare/master...release/0.3 +[unreleased]: https://github.com/Ptrskay3/axum-prometheus/compare/master...release/0.3.1 [0.2.0]: https://github.com/Ptrskay3/axum-prometheus/compare/9fb600d7d9ac2e6d38e6399119fc7ba7f25d5fe0...756dc67bf2baae2de406e012bdaa2334ce0fcdcb [0.3.0]: https://github.com/Ptrskay3/axum-prometheus/compare/axum-0.6...release/0.3 +[0.3.1]: https://github.com/Ptrskay3/axum-prometheus/compare/master...release/0.3.1 diff --git a/Cargo.toml b/Cargo.toml index 9195f00..a4515ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "axum-prometheus" -version = "0.3.0" +version = "0.3.1" edition = "2021" homepage = "https://github.com/Ptrskay3/axum-prometheus" license = "MIT" @@ -23,7 +23,7 @@ tokio = { version = "1.20.1", features = ["rt-multi-thread", "macros"] } tower-http = "0.3.4" bytes = "1.2.1" futures-core = "0.3.24" -matchit = "0.6" +matchit = "0.7" once_cell = "1.17.0" [dev-dependencies] diff --git a/README.md b/README.md index f6d4566..21f8957 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,8 @@ AXUM_HTTP_REQUESTS_DURATION_SECONDS = "my_app_requests_duration_seconds" AXUM_HTTP_REQUESTS_PENDING = "my_app_requests_pending" ``` +..or optionally use [`PrometheusMetricLayerBuilder::with_prefix`] function. + ### Compatibility | Axum Version | Crate Version | @@ -58,7 +60,7 @@ Add `axum-prometheus` to your `Cargo.toml`. ```toml [dependencies] -axum-prometheus = "0.3.0" +axum-prometheus = "0.3.1" ``` Then you instantiate the prometheus middleware: diff --git a/examples/builder-example/src/main.rs b/examples/builder-example/src/main.rs index 08dba57..f08b7ee 100644 --- a/examples/builder-example/src/main.rs +++ b/examples/builder-example/src/main.rs @@ -23,6 +23,7 @@ async fn main() { .init(); let (prometheus_layer, metric_handle) = PrometheusMetricLayerBuilder::new() + .with_prefix("builder-example") // ignore reporting requests that match "/metrics" .with_ignore_pattern("/metrics") // if the any of the second argument matches, report them at the `/foo` endpoint diff --git a/src/lib.rs b/src/lib.rs index 6965add..9888f2d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,6 +26,8 @@ //! AXUM_HTTP_REQUESTS_PENDING = "my_app_requests_pending" //! ``` //! +//! ..or optionally use [`PrometheusMetricLayerBuilder::with_prefix`] function. +//! //! ## Usage //! //! For more elaborate use-cases, see the builder-example that leverages [`PrometheusMetricLayerBuilder`]. @@ -33,7 +35,7 @@ //! Add `axum-prometheus` to your `Cargo.toml`. //! ```not_rust //! [dependencies] -//! axum-prometheus = "0.3.0" +//! axum-prometheus = "0.3.1" //! ``` //! //! Then you instantiate the prometheus middleware: @@ -115,8 +117,11 @@ pub const AXUM_HTTP_REQUESTS_TOTAL: &str = match option_env!("AXUM_HTTP_REQUESTS None => "axum_http_requests_total", }; +#[doc(hidden)] pub static PREFIXED_HTTP_REQUESTS_TOTAL: OnceCell = OnceCell::new(); +#[doc(hidden)] pub static PREFIXED_HTTP_REQUESTS_DURATION_SECONDS: OnceCell = OnceCell::new(); +#[doc(hidden)] pub static PREFIXED_HTTP_REQUESTS_PENDING: OnceCell = OnceCell::new(); use std::borrow::Cow;