axum-prometheus
A tower middleware to collect and export HTTP metrics for Axum
0.10.1
5.1M downloads/mo
#4473 most downloaded on crates.io
Ptrskay3/axum-prometheus
What this package is like to depend on
Last release 23 days ago
31 Jul 2026
Ships fairly regularly
a new release about every 4 months
Most releases are documented
notes for 13 of 16 stable releases
Nothing withdrawn
no release was ever pulled
4 years old
16 releases · first in 2022
2 releases in the last 12 months
see the full history below
Release timeline
16 releases · Sep 2022 to Jul 2026Releases
latest 16-
0.10.131 Jul 2026Release notes
Open source →What's Changed
- release/0.10.1 by @Ptrskay3 in #90
- fix: apply
with_prefixon the layer-onlybuild()path by @yacir in #91
New Contributors
Full Changelog: 0.10.0...0.10.1
Release notes
Open source →Fixed
with_prefixhas no effect when finalizing withbuild()[#91]
Changed
- Bump various dependencies to latest versions.
-
0.10.003 Jan 2026Release notes
Open source → -
0.9.013 Aug 2025Release notes
Open source →What's Changed
- Replace
pin-projectwithpin-project-liteby @FalkWoldmann in #80 - Bump metrics-exporter-prometheus version to 0.17 by @raimannma in #84
- feat: allow patterns by @erwanncloarec in #86
- bump various outdated dependencies by @Ptrskay3 in #87
New Contributors
- @raimannma made their first contribution in #84
- @erwanncloarec made their first contribution in #86
Full Changelog: 0.8.0...0.9.0
Release notes
Open source →Changed
- Add
MetricLayerBuilder::with_allow_patternandMetricLayerBuilder::with_allow_patternsto only report requests matching the given patterns. [#86] - Bump various outdated dependencies [#87]
- Replace
-
0.8.004 Jan 2025Release notes
Open source →0.8.0
Changed
- Compatibility with
axum = "0.8". This also updatesmatchitto0.8, changing how group patterns are described:
for example,with_group_patterns_as("/foo", &["/foo/:bar"])needs to be changed towith_group_patterns_as("/foo", &["/foo/{bar}"]).
The metrics values are also impacted: for example, the value"/foo/:bar"is now"/foo/{bar}".
This change bumps MSRV to 1.75. [#69] - Disable the default features in
metrics-exporter-prometheusto skip the binding of port 9000, and the upkeep task is manually spawned. [#75] - Add a new feature
http-listenerto enable that exact feature inmetrics-exporter-prometheus. [#79] - Replace the
once_celldependency withstd::sync::OnceLock[#78]
Fixed
Release notes
Open source →Changed
- Compatibility with
axum = "0.8". This also updatesmatchitto0.8, changing how group patterns are described: for example,with_group_patterns_as("/foo", &["/foo/:bar"])needs to be changed towith_group_patterns_as("/foo", &["/foo/{bar}"]). The metrics values are also impacted: for example, the value"/foo/:bar"is now"/foo/{bar}". This change bumps MSRV to 1.75. [#69] - Disable the default features in
metrics-exporter-prometheusto skip the binding of port 9000, and the upkeep task is manually spawned. [#75] - Add a new feature
http-listenerto enable that exact feature inmetrics-exporter-prometheus. [#79] - Replace the
once_celldependency withstd::sync::OnceLock[#78]
Fixed
- Fixed the long-standing pending requests metric leak. [#74]
- Removed the sideeffect of binding port 9000. [#75]
- Compatibility with
-
0.7.020 Jul 2024Release notes
Open source →Changed
MakeDefaultHandle::make_default_handlenow takesselfas argument. This allows custom implementor structs to hold non-static data. [#49]- Change the default initialization of
PrometheusHandleto prevent unbounded memory growth of histograms. [#52] - Bump
metricsto0.23,metrics-exporter-prometheusto0.15. [#52] - Document MSRV as 1.70 currently. [#52]
Added
GenericMetricLayer::pair_fromto initialize from a concrete struct.GenericMetricLayer::pairnow requires that the handle type implementsDefault. [#49]BaseMetricLayerthat serves a more lightweight alternative toGenericMetricLayer. [#56]
What's Changed
- Update metrics-exporter-prometheus to 0.14.0 by @gauravkumar37 in #50
MakeDefaultHandleand other API improvements by @Ptrskay3 in #49- Change default initialization of PrometheusHandle by @Ptrskay3 in #52
- A backend-agnostic layer by @Ptrskay3 in #56
- Briefly document push gateway mode by @Ptrskay3 in #61
- release/0.7.0 by @Ptrskay3 in #62
New Contributors
- @gauravkumar37 made their first contribution in #50
Full Changelog: 0.6.1...0.7.0
Release notes
Open source →Changed
MakeDefaultHandle::make_default_handlenow takesselfas argument. This allows custom implementor structs to hold non-static data. [#49]- Change the default initialization of
PrometheusHandleto prevent unbounded memory growth of histograms. [#52] - Bump
metricsto0.23,metrics-exporter-prometheusto0.15. [#52] - Document MSRV as 1.70 currently. [#52]
Added
GenericMetricLayer::pair_fromto initialize from a concrete struct.GenericMetricLayer::pairnow requires that the handle type implementsDefault. [#49]BaseMetricLayerthat serves a more lightweight alternative toGenericMetricLayer. [#56]
-
0.6.123 Jan 2024Release notes
Open source →- Disabled the
"push-gateway"feature inmetrics-exporter-prometheusby default, and added a way to enable it via
the same name underaxum_prometheus. This change ensures that this crate can still be built without openssl support, see here. [#44] - Update examples to
metrics-exporter-prometheusto0.13andmetricsto0.22. [#43]
Release notes
Open source →- Disabled the
"push-gateway"feature inmetrics-exporter-prometheusby default, and added a way to enable it via the same name underaxum_prometheus. This change ensures that this crate can still be built without openssl support, see here. [#44] - Update examples to
metrics-exporter-prometheusto0.13andmetricsto0.22. [#43]
- Disabled the
-
0.6.022 Jan 2024 -
0.5.027 Nov 2023Release notes
Open source →Added
- Support for response body size metric, which can be turned on via
PrometheusMetricLayerBuilder::enable_response_body_size. [#33] - All metrics now are initialized via the
metrics::describe_*functions by default, but can be turned off withPrometheusMetricLayerBuilder::no_initialize_metricsif you wish to do it manually. [#33] - Compatibility with
http-body = "1.0"andaxum = "0.7". [#36]
Changed
- The lower-level Lifecycle API has changed: separated the
OnBodyChunktrait, which is ran when a response body chunk has been generated. [#33]
Release notes
Open source →Added
- Support for response body size metric, which can be turned on via
PrometheusMetricLayerBuilder::enable_response_body_size. [#33] - All metrics now are initialized via
metrics::describe_*function by default, but can be turned off withPrometheusMetricLayerBuilder::no_initialize_metrics. [#33] - Compatibility with
http-body = "1.0"andaxum = "0.7". [#36]
Changed
- The lower-level Lifecycle API has changed: separated the
OnBodyChunktrait, which is ran when a response body chunk has been generated. [#\33]
- Support for response body size metric, which can be turned on via
-
0.4.024 Jul 2023Release notes
Open source →Added
- Support for different exporters than Prometheus. Developers now allowed to use their own exporter - as long as it's using the
metrics.rsecosystem. This is meant to be a non-breaking change - if you're using Prometheus, you shouldn't notice any changes in the public API. If you do however, please file an issue! #28 - An example showcasing
StatsDexporter #28 - Simple snapshot tests #28
- Utility functions to get metric names at runtime #28
Fixed
- Previous attempts to fix
PrometheusMetricBuilder::with_prefixin 0.3.4 were not complete, this is now fully addressed. #28
Release notes
Open source →Added
- Support for different exporters than Prometheus. Developers now allowed to use their own exporter - as long as it's using the
metrics.rsecosystem. This is meant to be a non-breaking change - if you're using Prometheus, you shouldn't notice any changes in the public API. If you do however, please file an issue! [#28] - An example showcasing
StatsDexporter [#28] - Simple snapshot tests [#28]
- Utility functions to get metric names at runtime [#28]
Fixed
- Previous attempts to fix
PrometheusMetricBuilder::with_prefixin 0.3.4 were not complete, this is now fully addressed. [#28]
- Support for different exporters than Prometheus. Developers now allowed to use their own exporter - as long as it's using the
-
0.3.416 Jul 2023Release notes
Open source →Fixed
PrometheusMetricBuilder::with_prefixis now properly setting the metric prefix, and the metric handle also takes that prefix into account. Previously the metric initialization incorrectly ignored the prefix, which caused the requests duration histogram to usequantileinstead oflelabels. [#26]. (Thanks @yanns!)
Release notes
Open source →Fixed
PrometheusMetricBuilder::with_prefixis now properly setting the metric prefix, and the metric handle also takes that prefix into account. Previously the metric initialization incorrectly ignored the prefix, which caused the requests duration histogram to usequantileinstead oflelabels.
-
0.3.302 May 2023 -
0.3.225 Mar 2023Release notes
Open source →Added
- The status code of the response is now captured in the total requests counter metric.
-
0.3.116 Feb 2023Release notes
Open source →Added
with_prefixtoPrometheusMetricLayerBuilder, 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 oneaxum_prometheusinstance (since environment variables don't work there).
0.3.0 - 2023-01-04
Added
-
Routing patterns can be ignored, and grouped together when reporting to Prometheus.
-
Endpoint label behavior can be altered with the new
EndpointLabelenum. -
Added a new builder
PrometheusMetricLayerBuilderto easily customize these.let (prometheus_layer, metric_handle) = PrometheusMetricLayerBuilder::new() // ignore reporting requests that match "/foo" or "/sensitive" .with_ignore_patterns(&["/foo", "/sensitive"]) // if the any of the second argument matches, report them at the `/bar` endpoint .with_group_patterns_as("/bar", &["/foo/:bar", "/foo/:bar/:baz"]) // use `axum::extract::MatchedPath`, and if that fails, use the exact requested URI .with_endpoint_label_type(EndpointLabel::MatchedPath) .with_default_metrics() .build_pair(); -
A builder-example and an endpoint-type-example.
-
The metric names can be changed by setting some environmental variables at compile time. It is best to set these in the
config.toml(note this is not the same file asCargo.toml):[env] AXUM_HTTP_REQUESTS_TOTAL = "my_app_requests_total" AXUM_HTTP_REQUESTS_DURATION_SECONDS = "my_app_requests_duration_seconds" AXUM_HTTP_REQUESTS_PENDING = "my_app_requests_pending"
0.2.0 - 2022-10-25
Added
- Compatibility with
axum-core = "0.3"and thusaxum = "0.6".
0.1.0
First version.
-
0.3.004 Jan 2023Nothing published for this version
-
0.2.025 Nov 2022Nothing published for this version
-
0.1.020 Sep 2022Nothing published for this version