axum-otel-metrics

Build status Crates.io Documentation

axum OpenTelemetry metrics middleware with prometheus exporter

axum is an ergonomic and modular web framework built with Tokio, Tower, and Hyper

be default, the metrics will be exported at /metrics endpoint. and below metrics will be exported:

requestdurationseconds histogram request_duration_seconds_bucket request_duration_seconds_sum request_duration_seconds_count

requests_total counter

requests_total

labels for request_duration_seconds and requests_total:

method path status

Usage

```rust use axumotelmetrics::HttpMetricsLayerBuilder;

let metrics = HttpMetricsLayerBuilder::new() .build();

let app = Router::new() // export metrics at /metrics endpoint .merge(metrics.routes()) .route("/", get(handler)) .route("/hello", get(handler)) .route("/world", get(handler)) // add the metrics middleware .layer(metrics); ```

Usage with State

```rust use axumotelmetrics::HttpMetricsLayerBuilder;

[derive(Clone)]

pub struct SharedState { }

let state = SharedState { };

let metrics = HttpMetricsLayerBuilder::new() .build();

let app = Router::new() // export metrics at /metrics endpoint .merge(metrics.routes::()) .route("/", get(handler)) .route("/hello", get(handler)) .route("/world", get(handler)) // add the metrics middleware .layer(metrics) .with_state(state.clone()); ```

OpenTelemetry Rust Instrumentation Status and Releases

https://opentelemetry.io/docs/instrumentation/rust/#status-and-releases

| Traces | Metrics | Logs | |--------------------------------------------------------------------------------------------------|---------|---------------------| | Stable | Alpha | Not yet implemented |

OpenTelemetry Metrics Exporter

Push Metric Exporter https://opentelemetry.io/docs/reference/specification/metrics/sdk/#push-metric-exporter

Pull Metric Exporter https://opentelemetry.io/docs/reference/specification/metrics/sdk/#pull-metric-exporter

exporters

https://opentelemetry.io/docs/reference/specification/metrics/sdk_exporters/

In-memory https://opentelemetry.io/docs/reference/specification/metrics/sdk_exporters/in-memory/

Prometheus https://opentelemetry.io/docs/reference/specification/metrics/sdk_exporters/prometheus/

OTLP https://opentelemetry.io/docs/reference/specification/metrics/sdk_exporters/otlp/

Standard output https://opentelemetry.io/docs/reference/specification/metrics/sdk_exporters/stdout/

Metrics Data Model

https://opentelemetry.io/docs/reference/specification/metrics/data-model/