Skip to content

Commit

Permalink
refactor: derive default for HttpMetricsLayerBuilder
Browse files Browse the repository at this point in the history
Replace custom Default implementation with #[derive(Default)] for HttpMetricsLayerBuilder.
  • Loading branch information
ttys3 committed Jan 7, 2025
1 parent cfad617 commit 431dfbb
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//! [axum](https://github.com/tokio-rs/axum) OpenTelemetry Metrics middleware
//!
//! ## Simple Usage
//!
//!
//! Meter provider should be configured through [opentelemetry_sdk `global::set_meter_provider`](https://docs.rs/opentelemetry/0.27.1/opentelemetry/global/index.html#global-metrics-api).
//! if you want to use the [prometheus exporter](https://opentelemetry.io/docs/specs/otel/metrics/sdk_exporters/prometheus/), see [Advanced Usage](#advanced-usage) below.
//!
//!
//! ```
//! use axum_otel_metrics::HttpMetricsLayerBuilder;
//! use axum::{response::Html, routing::get, Router};
//!
//!
//! let metrics = HttpMetricsLayerBuilder::new()
//! .build();
//!
Expand All @@ -25,9 +25,9 @@
//! ```
//!
//! ## Advanced Usage
//!
//!
//! this is an example to use the [prometheus exporter](https://opentelemetry.io/docs/specs/otel/metrics/sdk_exporters/prometheus/)
//!
//!
//! it will export the metrics at `/metrics` endpoint
//!
//! ```
Expand Down Expand Up @@ -67,16 +67,16 @@
use axum::http::Response;
use axum::{extract::MatchedPath, http, http::Request};
use std::env;
use std::sync::Arc;
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use std::task::Poll::Ready;
use std::task::{Context, Poll};
use std::time::Instant;

use opentelemetry::KeyValue;
use opentelemetry::metrics::{Histogram, UpDownCounter};
use opentelemetry::global;
use opentelemetry::metrics::{Histogram, UpDownCounter};
use opentelemetry::KeyValue;

use tower::{Layer, Service};

Expand Down Expand Up @@ -200,21 +200,12 @@ impl Default for PathSkipper {
}
}

#[derive(Clone)]
#[derive(Clone, Default)]
pub struct HttpMetricsLayerBuilder {
skipper: PathSkipper,
is_tls: bool,
}

impl Default for HttpMetricsLayerBuilder {
fn default() -> Self {
Self {
skipper: PathSkipper::default(),
is_tls: false,
}
}
}

impl HttpMetricsLayerBuilder {
pub fn new() -> Self {
HttpMetricsLayerBuilder::default()
Expand Down Expand Up @@ -330,7 +321,7 @@ where
return "https".to_string();
}
if let Some(scheme) = req.headers().get("X-Url-Scheme") {
scheme.to_str().unwrap().to_string()
scheme.to_str().unwrap().to_string()
} else {
"http".to_string()
}
Expand Down Expand Up @@ -527,8 +518,7 @@ mod tests {
#[derive(Clone)]
struct AppState {}

let metrics = HttpMetricsLayerBuilder::new()
.build();
let metrics = HttpMetricsLayerBuilder::new().build();
let _app: Router<AppState> = Router::new()
.route(
"/metrics",
Expand Down

0 comments on commit 431dfbb

Please sign in to comment.