{"id":16612901,"url":"https://github.com/ttys3/axum-otel-metrics","last_synced_at":"2025-10-11T17:28:23.222Z","repository":{"id":61432536,"uuid":"550469000","full_name":"ttys3/axum-otel-metrics","owner":"ttys3","description":"axum OpenTelemetry Metrics middleware with prometheus exporter","archived":false,"fork":false,"pushed_at":"2025-09-29T16:01:26.000Z","size":364,"stargazers_count":34,"open_issues_count":13,"forks_count":9,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-10T08:51:12.416Z","etag":null,"topics":["axum","axum-middleware","metric","metrics","middleware","opentelemetry","prometheus"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ttys3.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-10-12T20:26:40.000Z","updated_at":"2025-09-10T22:38:20.000Z","dependencies_parsed_at":"2023-02-19T07:30:44.886Z","dependency_job_id":"6756d3e4-c1a9-4337-890d-64d8d137f9f2","html_url":"https://github.com/ttys3/axum-otel-metrics","commit_stats":{"total_commits":74,"total_committers":3,"mean_commits":"24.666666666666668","dds":"0.20270270270270274","last_synced_commit":"614301058be208ce18b765f3aa7fd4a599c90396"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/ttys3/axum-otel-metrics","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttys3%2Faxum-otel-metrics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttys3%2Faxum-otel-metrics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttys3%2Faxum-otel-metrics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttys3%2Faxum-otel-metrics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ttys3","download_url":"https://codeload.github.com/ttys3/axum-otel-metrics/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttys3%2Faxum-otel-metrics/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279008115,"owners_count":26084396,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["axum","axum-middleware","metric","metrics","middleware","opentelemetry","prometheus"],"created_at":"2024-10-12T01:45:16.748Z","updated_at":"2025-10-11T17:28:23.216Z","avatar_url":"https://github.com/ttys3.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# axum-otel-metrics\n\n[![Build status](https://github.com/ttys3/axum-otel-metrics/actions/workflows/rust.yml/badge.svg?branch=main)](https://github.com/ttys3/axum-otel-metrics/actions/workflows/rust.yml)\n[![Crates.io](https://img.shields.io/crates/v/axum-otel-metrics)](https://crates.io/crates/axum-otel-metrics)\n[![Documentation](https://docs.rs/axum-otel-metrics/badge.svg)](https://docs.rs/axum-otel-metrics)\n\naxum OpenTelemetry metrics middleware with OTLP exporter\n\nfollows [Semantic Conventions for HTTP Metrics](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-metrics.md)\n\n[axum](https://github.com/tokio-rs/axum) is an ergonomic and modular web framework built with Tokio, Tower, and Hyper\n\n## Note: Prometheus exporter is removed now\n\n\u003e Development of the Prometheus exporter has been discontinued. See the related\n\u003e [issue](https://github.com/open-telemetry/opentelemetry-rust/issues/2451). This\n\u003e crate depends on the unmaintained `protobuf` crate and has unresolved security\n\u003e vulnerabilities. Version 0.29 will be the final release.\n\u003e \n\u003e For Prometheus integration, we strongly recommend using the [OTLP] exporter\n\u003e instead. Prometheus [natively supports\n\u003e OTLP](https://prometheus.io/docs/guides/opentelemetry/#enable-the-otlp-receiver),\n\u003e providing a more stable and actively maintained solution.\n\u003e for more details please check https://github.com/open-telemetry/opentelemetry-rust/blob/opentelemetry-0.30.0/opentelemetry-prometheus/README.md\n\u003e and https://github.com/ttys3/axum-otel-metrics/issues/176\n\n\n## Usage\n\nUses the [OTLP Exporter](https://opentelemetry.io/docs/specs/otel/metrics/sdk_exporters/otlp/) to send metrics to OpenTelemetry collector.\n\nYou can configure it via environment variables:\n- `OTEL_EXPORTER_OTLP_ENDPOINT` or `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`\n\n`OTEL_EXPORTER_OTLP_ENDPOINT` default value:\n- gRPC: `http://localhost:4317`\n- HTTP: `http://localhost:4318`\n\n`OTEL_EXPORTER_OTLP_METRICS_ENDPOINT` default value:\n- gRPC: `http://localhost:4317`\n- HTTP: `http://localhost:4318/v1/metrics`\n\n\u003e For more details, see https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#endpoint-configuration\n\n```rust\nuse axum_otel_metrics::HttpMetricsLayerBuilder;\nuse axum::{response::Html, routing::get, Router};\nuse opentelemetry_sdk::metrics::{PeriodicReader, SdkMeterProvider, Temporality};\nuse opentelemetry::global;\n \nlet exporter = opentelemetry_otlp::MetricExporter::builder()\n    .with_http()\n    .with_temporality(Temporality::default())\n    .build()\n    .unwrap();\n \nlet reader = PeriodicReader::builder(exporter)\n    .with_interval(std::time::Duration::from_secs(30))\n    .build();\n\nlet provider = SdkMeterProvider::builder()\n    .with_reader(reader)\n    .build();\n\n// TODO: ensure defer run `provider.shutdown()?;`\n\nglobal::set_meter_provider(provider.clone());\n\nlet metrics = HttpMetricsLayerBuilder::new()\n    .build();\n\nlet app = Router::new()\n    .route(\"/\", get(handler))\n    .route(\"/hello\", get(handler))\n    .route(\"/world\", get(handler))\n    // add the metrics middleware\n    .layer(metrics);\n\nasync fn handler() -\u003e Html\u003c\u0026'static str\u003e {\n    Html(\"\u003ch1\u003eHello, World!\u003c/h1\u003e\")\n}\n```\n\n## Exported Metrics\n\nThe following metrics are exported following OpenTelemetry semantic conventions:\n\n**http.server.active_requests** (UpDownCounter)\n- The number of active HTTP requests\n- Labels: `http.request.method`, `url.scheme`\n\n**http.server.request.duration** (Histogram) \n- The HTTP request latencies in seconds\n- Labels: `http.request.method`, `http.route`, `http.response.status_code`, `server.address`\n\n**http.server.request.body.size** (Histogram)\n- The HTTP request sizes in bytes  \n- Labels: `http.request.method`, `http.route`, `http.response.status_code`, `server.address`\n\n**http.server.response.body.size** (Histogram)\n- The HTTP response sizes in bytes\n- Labels: `http.request.method`, `http.route`, `http.response.status_code`, `server.address`\n\n## OpenTelemetry Rust Instrumentation Status and Releases\n\nhttps://opentelemetry.io/docs/instrumentation/rust/#status-and-releases\n\n| Traces | Metrics | Logs |\n|--------|---------|------|\n| [Beta](https://github.com/open-telemetry/oteps/blob/main/text/0232-maturity-of-otel.md#beta) | Beta | Beta |\n\n## OpenTelemetry Metrics Exporter\n\n**Push Metric Exporter** https://opentelemetry.io/docs/reference/specification/metrics/sdk/#push-metric-exporter\n\n**Pull Metric Exporter** https://opentelemetry.io/docs/reference/specification/metrics/sdk/#pull-metric-exporter\n\n### exporters\n\nhttps://opentelemetry.io/docs/reference/specification/metrics/sdk_exporters/\n\n- In-memory https://opentelemetry.io/docs/reference/specification/metrics/sdk_exporters/in-memory/\n- OTLP https://opentelemetry.io/docs/reference/specification/metrics/sdk_exporters/otlp/\n- Standard output https://opentelemetry.io/docs/reference/specification/metrics/sdk_exporters/stdout/\n\nwhere is prometheus exporter?\n\n\n## Metrics Data Model\n\nhttps://opentelemetry.io/docs/reference/specification/metrics/data-model/\n\n## Related Projects\n\n- https://github.com/nlopes/actix-web-prom - Actix-web middleware to expose Prometheus metrics\n- https://github.com/sd2k/rocket_prometheus - Prometheus fairing and handler for Rocket\n- https://github.com/Ptrskay3/axum-prometheus - axum-prometheus relies on metrics.rs and its ecosystem to collect and export metrics\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fttys3%2Faxum-otel-metrics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fttys3%2Faxum-otel-metrics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fttys3%2Faxum-otel-metrics/lists"}