From 034a4b2ef4bc4562077656b3264efebb9e3c2d1c Mon Sep 17 00:00:00 2001 From: Christopher Kolstad Date: Mon, 27 Nov 2023 15:52:16 +0100 Subject: [PATCH] fix: readd http metrics (#351) After upgrading opentelemetry we lost our http metrics on our prometheus metrics dump due to a different call setup for getting it to work. This PR again sets up our configured meter provider to be used for all prometheus metrics. Which allows us to have our custom middleware work again. --- server/src/metrics/actix_web_metrics.rs | 3 +-- server/src/prom_metrics.rs | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/server/src/metrics/actix_web_metrics.rs b/server/src/metrics/actix_web_metrics.rs index 2a2b1965..c66fa815 100644 --- a/server/src/metrics/actix_web_metrics.rs +++ b/server/src/metrics/actix_web_metrics.rs @@ -273,7 +273,7 @@ impl RequestMetricsBuilder { /// construct meters for this crate fn get_versioned_meter(meter_provider: impl MeterProvider) -> Meter { meter_provider.versioned_meter( - "actix_web_opentelemetry", + "unleash_edge", Some(env!("CARGO_PKG_VERSION")), Some(opentelemetry_semantic_conventions::SCHEMA_URL), None, @@ -384,7 +384,6 @@ where timer.elapsed().map(|t| t.as_secs_f64()).unwrap_or_default(), &attributes, ); - Ok(res) } else { res diff --git a/server/src/prom_metrics.rs b/server/src/prom_metrics.rs index bb70b728..07efd1f8 100644 --- a/server/src/prom_metrics.rs +++ b/server/src/prom_metrics.rs @@ -1,5 +1,7 @@ use crate::cli::LogFormat; +use opentelemetry::global; use opentelemetry_sdk::metrics::MeterProvider; +use opentelemetry_semantic_conventions::resource::SERVICE_NAME; #[cfg(target_os = "linux")] use prometheus::process_collector::ProcessCollector; use tracing_subscriber::layer::SubscriberExt; @@ -47,11 +49,19 @@ fn instantiate_prometheus_metrics_handler( registry: prometheus::Registry, ) -> (PrometheusMetricsHandler, RequestMetrics) { let resource = opentelemetry_sdk::Resource::new(vec![ - opentelemetry::KeyValue::new("service.name", "unleash-edge"), - opentelemetry::KeyValue::new("edge.version", crate::types::build::PKG_VERSION), - opentelemetry::KeyValue::new("edge.githash", crate::types::build::SHORT_COMMIT), + opentelemetry::KeyValue::new(SERVICE_NAME, "unleash-edge"), + opentelemetry::KeyValue::new("edge_version", crate::types::build::PKG_VERSION), + opentelemetry::KeyValue::new("edge_githash", crate::types::build::SHORT_COMMIT), ]); - let provider = MeterProvider::builder().with_resource(resource).build(); + let exporter = opentelemetry_prometheus::exporter() + .with_registry(registry.clone()) + .build() + .expect("Failed to setup prometheus"); + let provider = MeterProvider::builder() + .with_resource(resource) + .with_reader(exporter) + .build(); + global::set_meter_provider(provider.clone()); ( PrometheusMetricsHandler::new(registry), RequestMetricsBuilder::new()