Skip to content

Commit 1e7e344

Browse files
fix: call set_meter_provider to setup metrics
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
1 parent 90ba187 commit 1e7e344

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/metrics.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use opentelemetry::{metrics, KeyValue};
1+
use anyhow::Result;
2+
use opentelemetry::{global, KeyValue};
23
use opentelemetry_otlp::{ExportConfig, WithExportConfig};
3-
use opentelemetry_sdk::metrics::SdkMeterProvider;
44
use opentelemetry_sdk::runtime;
55

66
mod policy_evaluations_total;
@@ -10,15 +10,19 @@ pub use policy_evaluations_latency::record_policy_latency;
1010

1111
const METER_NAME: &str = "kubewarden";
1212

13-
pub fn setup_metrics() -> metrics::Result<SdkMeterProvider> {
14-
opentelemetry_otlp::new_pipeline()
13+
pub fn setup_metrics() -> Result<()> {
14+
let meter_provider = opentelemetry_otlp::new_pipeline()
1515
.metrics(runtime::Tokio)
1616
.with_exporter(
1717
opentelemetry_otlp::new_exporter()
1818
.tonic()
1919
.with_export_config(ExportConfig::default()),
2020
)
21-
.build()
21+
.build()?;
22+
23+
global::set_meter_provider(meter_provider.clone());
24+
25+
Ok(())
2226
}
2327

2428
pub trait PolicyEvaluationMetric: Into<Vec<KeyValue>> {}

0 commit comments

Comments
 (0)