14 releases (8 breaking)

new 0.9.1 Dec 10, 2024
0.9.0-alpha.2 Aug 4, 2024
0.9.0-alpha.1 Apr 6, 2024
0.8.0 Nov 27, 2023
0.2.0 Nov 25, 2022

#67 in HTTP server

Download history 429/week @ 2024-08-20 326/week @ 2024-08-27 449/week @ 2024-09-03 421/week @ 2024-09-10 679/week @ 2024-09-17 598/week @ 2024-09-24 672/week @ 2024-10-01 444/week @ 2024-10-08 697/week @ 2024-10-15 429/week @ 2024-10-22 380/week @ 2024-10-29 761/week @ 2024-11-05 1022/week @ 2024-11-12 942/week @ 2024-11-19 1083/week @ 2024-11-26 775/week @ 2024-12-03

3,887 downloads per month

MIT license

35KB
479 lines

axum-otel-metrics

Build status Crates.io Documentation

axum OpenTelemetry metrics middleware

supported exporters:

follow Semantic Conventions for HTTP Metrics

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

Usage

by default, it will use the OTLP Exporter you can config it via env var: OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_METRICS_ENDPOINT

OTEL_EXPORTER_OTLP_ENDPOINT default value:

gRPC: http://localhost:4317

HTTP: http://localhost:4318

OTEL_EXPORTER_OTLP_METRICS_ENDPOINT default value:

gRPC: http://localhost:4317

HTTP: http://localhost:4318/v1/metrics

for more details, see https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#endpoint-configuration

use axum_otel_metrics::HttpMetricsLayerBuilder;

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

let app = Router::new()
    .route("/", get(handler))
    .route("/hello", get(handler))
    .route("/world", get(handler))
    // add the metrics middleware
    .layer(metrics);

Prometheus Exporter

check the doc Advanced Usage section to see how to use the prometheus exporter

for prometheus exporter, 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

OpenTelemetry Rust Instrumentation Status and Releases

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

Traces Metrics Logs
Beta Beta Beta

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/

https://github.com/nlopes/actix-web-prom

Actix-web middleware to expose Prometheus metrics

https://github.com/sd2k/rocket_prometheus

Prometheus fairing and handler for Rocket

https://github.com/Ptrskay3/axum-prometheus

axum-prometheus relies on metrics.rs and its ecosystem to collect and export metrics - for instance for Prometheus, metrics_exporter_prometheus is used as a backend to interact with Prometheus.

Dependencies

~12–23MB
~335K SLoC