#axum #opentelemetry #otel #middleware #metrics #open-telemetry #axum-middleware

axum-otel-metrics

axum OpenTelemetry metrics middleware with prometheus exporter

7 releases (breaking)

0.6.0 Aug 9, 2023
0.5.0 Jul 31, 2023
0.4.0 May 4, 2023
0.3.0 Mar 22, 2023
0.1.5 Oct 14, 2022

#153 in HTTP server

Download history 247/week @ 2023-06-03 318/week @ 2023-06-10 361/week @ 2023-06-17 300/week @ 2023-06-24 186/week @ 2023-07-01 43/week @ 2023-07-08 27/week @ 2023-07-15 24/week @ 2023-07-22 69/week @ 2023-07-29 67/week @ 2023-08-05 20/week @ 2023-08-12 60/week @ 2023-08-19 48/week @ 2023-08-26 97/week @ 2023-09-02 87/week @ 2023-09-09 56/week @ 2023-09-16

289 downloads per month

MIT license

29KB
427 lines

axum-otel-metrics

Build status Crates.io Documentation

axum OpenTelemetry metrics middleware with prometheus exporter

follow Semantic Conventions for HTTP Metrics

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:

requests_total counter

requests_total

http_server_active_requests gauge

The number of active HTTP requests

http_server_request_duration_seconds histogram

http_server_request_duration_seconds_bucket
http_server_request_duration_seconds_sum
http_server_request_duration_seconds_count

http_server_request_size_bytes histogram

http_server_request_size_bytes_bucket
http_server_request_size_bytes_sum
http_server_request_size_bytes_count

http_server_response_size_bytes_ histogram

http_server_response_size_bytes__bucket
http_server_response_size_bytes__sum
http_server_response_size_bytes__count

labels for requests_total, http_server_request_duration_seconds, http_server_request_size_bytes, http_server_response_size_bytes :

http_request_method
http_route
http_response_status_code
server_address

labels for http_server_active_requests :

http_request_method
url_scheme

Usage

use axum_otel_metrics::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

use axum_otel_metrics::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::<SharedState>())
    .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/

Dependencies

~12–26MB
~339K SLoC