Skip to content

Commit

Permalink
fix: readd http metrics (#351)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Christopher Kolstad authored Nov 27, 2023
1 parent 3618299 commit 034a4b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
3 changes: 1 addition & 2 deletions server/src/metrics/actix_web_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -384,7 +384,6 @@ where
timer.elapsed().map(|t| t.as_secs_f64()).unwrap_or_default(),
&attributes,
);

Ok(res)
} else {
res
Expand Down
18 changes: 14 additions & 4 deletions server/src/prom_metrics.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 034a4b2

Please sign in to comment.