Skip to content

Commit

Permalink
stabilize to 0.1.0 with stablization of otel http metric conventions
Browse files Browse the repository at this point in the history
update docs with new constructor signature
  • Loading branch information
francoposa committed Dec 12, 2023
1 parent ef2cb7b commit a7be3b4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tower-otel-http-metrics"
edition = "2021"
version = "0.1.0-alpha.3"
version = "0.1.0"
license = "MIT"
description = "OpenTelemetry Metrics Middleware for Tower-compatible Rust HTTP servers"
homepage = "https://github.com/francoposa/tower-otel-http-metrics"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async fn main() {

// init our otel metrics middleware
let otel_metrics_service_layer =
tower_otel_http_metrics::HTTPMetricsLayer::new(String::from(SERVICE_NAME), None);
tower_otel_http_metrics::HTTPMetricsLayer::new(String::from(SERVICE_NAME));

let app = Router::new()
.route("/", get(handle))
Expand Down Expand Up @@ -146,7 +146,7 @@ async fn main() {

// init our otel metrics middleware
let otel_metrics_service_layer =
tower_otel_http_metrics::HTTPMetricsLayer::new(String::from(SERVICE_NAME), None);
tower_otel_http_metrics::HTTPMetricsLayer::new(String::from(SERVICE_NAME));

let service = ServiceBuilder::new()
.layer(otel_metrics_service_layer)
Expand Down
2 changes: 1 addition & 1 deletion examples/axum-http-service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async fn main() {

// init our otel metrics middleware
let otel_metrics_service_layer =
tower_otel_http_metrics::HTTPMetricsLayer::new(String::from(SERVICE_NAME), None);
tower_otel_http_metrics::HTTPMetricsLayer::new(String::from(SERVICE_NAME));

let app = Router::new()
.route("/", get(handle))
Expand Down
2 changes: 1 addition & 1 deletion examples/tower-http-service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async fn main() {

// init our otel metrics middleware
let otel_metrics_service_layer =
tower_otel_http_metrics::HTTPMetricsLayer::new(String::from(SERVICE_NAME), None);
tower_otel_http_metrics::HTTPMetricsLayer::new(String::from(SERVICE_NAME));

let service = ServiceBuilder::new()
.layer(otel_metrics_service_layer)
Expand Down
14 changes: 5 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use opentelemetry_api::global;
use pin_project_lite::pin_project;
use tower::{Layer, Service};

const HTTP_SERVER_DURATION_METRIC: &str = "http.server.duration";
const HTTP_SERVER_DURATION_METRIC: &str = "http.server.request.duration";

const HTTP_REQUEST_METHOD_LABEL: &str = "http.request.method";
const HTTP_ROUTE_LABEL: &str = "http.route";
Expand Down Expand Up @@ -56,17 +56,13 @@ pub struct HTTPMetricsLayer {
}

impl HTTPMetricsLayer {
// TODO convert this to a bunch of "with_whatever()" methods
pub fn new(service_name: String, server_duration_metric_name: Option<String>) -> Self {
pub fn new(service_name: String) -> Self {
let meter = global::meter(service_name);

let mut _server_duration_metric_name = Cow::from(HTTP_SERVER_DURATION_METRIC);
if let Some(name) = server_duration_metric_name {
_server_duration_metric_name = name.into();
}
HTTPMetricsLayer {
state: Arc::from(HTTPMetricsLayerState {
server_request_duration: meter.u64_histogram(_server_duration_metric_name).init(),
server_request_duration: meter
.u64_histogram(Cow::from(HTTP_SERVER_DURATION_METRIC))
.init(),
}),
}
}
Expand Down

0 comments on commit a7be3b4

Please sign in to comment.