From e91f7f25586a5770d7b7d5ca25aba88750481ca8 Mon Sep 17 00:00:00 2001 From: slim Date: Tue, 8 Oct 2024 18:09:53 +0100 Subject: [PATCH] feat: update otel versions for promo to 0.26 --- opentelemetry-prometheus/CHANGELOG.md | 4 + opentelemetry-prometheus/Cargo.toml | 6 +- opentelemetry-prometheus/src/config.rs | 24 +---- opentelemetry-prometheus/src/lib.rs | 10 +-- .../tests/integration_test.rs | 88 +++++++++---------- 5 files changed, 54 insertions(+), 78 deletions(-) diff --git a/opentelemetry-prometheus/CHANGELOG.md b/opentelemetry-prometheus/CHANGELOG.md index da42c5d26e..4d446beb29 100644 --- a/opentelemetry-prometheus/CHANGELOG.md +++ b/opentelemetry-prometheus/CHANGELOG.md @@ -3,6 +3,10 @@ ## vNext - Bump MSRV to 1.70 [#2179](https://github.com/open-telemetry/opentelemetry-rust/pull/2179) +- Update `opentelemetry` dependency version to 0.26 +- Update `opentelemetry_sdk` dependency version to 0.26 +- Update `opentelemetry-semantic-conventions` dependency version to 0.26 + ## v0.17.0 diff --git a/opentelemetry-prometheus/Cargo.toml b/opentelemetry-prometheus/Cargo.toml index 5c22b49124..71d296bdf2 100644 --- a/opentelemetry-prometheus/Cargo.toml +++ b/opentelemetry-prometheus/Cargo.toml @@ -21,13 +21,13 @@ rustdoc-args = ["--cfg", "docsrs"] [dependencies] once_cell = { workspace = true } -opentelemetry = { version = "0.24", default-features = false, features = ["metrics"] } -opentelemetry_sdk = { version = "0.24", default-features = false, features = ["metrics"] } +opentelemetry = { version = "0.26", default-features = false, features = ["metrics"] } +opentelemetry_sdk = { version = "0.26", default-features = false, features = ["metrics"] } prometheus = "0.13" protobuf = "2.14" [dev-dependencies] -opentelemetry-semantic-conventions = { version = "0.16" } +opentelemetry-semantic-conventions = { version = "0.26" } http-body-util = { workspace = true } hyper = { workspace = true, features = ["full"] } hyper-util = { workspace = true, features = ["full"] } diff --git a/opentelemetry-prometheus/src/config.rs b/opentelemetry-prometheus/src/config.rs index 0143e59692..40d6f6779b 100644 --- a/opentelemetry-prometheus/src/config.rs +++ b/opentelemetry-prometheus/src/config.rs @@ -1,10 +1,7 @@ use core::fmt; use once_cell::sync::OnceCell; use opentelemetry::metrics::{MetricsError, Result}; -use opentelemetry_sdk::metrics::{ - reader::{AggregationSelector, MetricProducer}, - ManualReaderBuilder, -}; +use opentelemetry_sdk::metrics::ManualReaderBuilder; use std::sync::{Arc, Mutex}; use crate::{Collector, PrometheusExporter, ResourceSelector}; @@ -105,16 +102,6 @@ impl ExporterBuilder { self } - /// Configure the [AggregationSelector] the exporter will use. - /// - /// If no selector is provided, the [DefaultAggregationSelector] is used. - /// - /// [DefaultAggregationSelector]: opentelemetry_sdk::metrics::reader::DefaultAggregationSelector - pub fn with_aggregation_selector(mut self, agg: impl AggregationSelector + 'static) -> Self { - self.reader = self.reader.with_aggregation_selector(agg); - self - } - /// Configures whether to export resource as attributes with every metric. /// /// Note that this is orthogonal to the `target_info` metric, which can be disabled using `without_target_info`. @@ -128,15 +115,6 @@ impl ExporterBuilder { self } - /// Registers an external [MetricProducer] with this reader. - /// - /// The producer is used as a source of aggregated metric data which is - /// incorporated into metrics collected from the SDK. - pub fn with_producer(mut self, producer: impl MetricProducer + 'static) -> Self { - self.reader = self.reader.with_producer(producer); - self - } - /// Creates a new [PrometheusExporter] from this configuration. pub fn build(self) -> Result { let reader = Arc::new(self.reader.build()); diff --git a/opentelemetry-prometheus/src/lib.rs b/opentelemetry-prometheus/src/lib.rs index 64cf6e5266..28383d6beb 100644 --- a/opentelemetry-prometheus/src/lib.rs +++ b/opentelemetry-prometheus/src/lib.rs @@ -105,8 +105,8 @@ use opentelemetry::{ use opentelemetry_sdk::{ metrics::{ data::{self, ResourceMetrics, Temporality}, - reader::{AggregationSelector, MetricReader, TemporalitySelector}, - Aggregation, InstrumentKind, ManualReader, Pipeline, + reader::{MetricReader, TemporalitySelector}, + InstrumentKind, ManualReader, Pipeline, }, Resource, Scope, }; @@ -160,12 +160,6 @@ impl TemporalitySelector for PrometheusExporter { } } -impl AggregationSelector for PrometheusExporter { - fn aggregation(&self, kind: InstrumentKind) -> Aggregation { - self.reader.aggregation(kind) - } -} - impl MetricReader for PrometheusExporter { fn register_pipeline(&self, pipeline: Weak) { self.reader.register_pipeline(pipeline) diff --git a/opentelemetry-prometheus/tests/integration_test.rs b/opentelemetry-prometheus/tests/integration_test.rs index 906290a092..529867e6a9 100644 --- a/opentelemetry-prometheus/tests/integration_test.rs +++ b/opentelemetry-prometheus/tests/integration_test.rs @@ -46,10 +46,10 @@ fn prometheus_exporter_integration() { expected_file: "counter.txt", record_metrics: Box::new(|meter| { let attrs = vec![ - Key::new("A").string("B"), - Key::new("C").string("D"), - Key::new("E").bool(true), - Key::new("F").i64(42), + KeyValue::new("A", "B"), + KeyValue::new("C", "D"), + KeyValue::new("E", true), + KeyValue::new("F", 42), ]; let counter = meter .f64_counter("foo") @@ -60,10 +60,10 @@ fn prometheus_exporter_integration() { counter.add(10.3, &attrs); counter.add(9.0, &attrs); let attrs2 = vec![ - Key::new("A").string("D"), - Key::new("C").string("B"), - Key::new("E").bool(true), - Key::new("F").i64(42), + KeyValue::new("A", "D"), + KeyValue::new("C", "B"), + KeyValue::new("E", true), + KeyValue::new("F", 42), ]; counter.add(5.0, &attrs2); }), @@ -75,10 +75,10 @@ fn prometheus_exporter_integration() { builder: ExporterBuilder::default().without_counter_suffixes(), record_metrics: Box::new(|meter| { let attrs = vec![ - Key::new("A").string("B"), - Key::new("C").string("D"), - Key::new("E").bool(true), - Key::new("F").i64(42), + KeyValue::new("A", "B"), + KeyValue::new("C", "D"), + KeyValue::new("E", true), + KeyValue::new("F", 42), ]; let counter = meter .f64_counter("foo") @@ -89,10 +89,10 @@ fn prometheus_exporter_integration() { counter.add(10.3, &attrs); counter.add(9.0, &attrs); let attrs2 = vec![ - Key::new("A").string("D"), - Key::new("C").string("B"), - Key::new("E").bool(true), - Key::new("F").i64(42), + KeyValue::new("A", "D"), + KeyValue::new("C", "B"), + KeyValue::new("E", true), + KeyValue::new("F", 42), ]; counter.add(5.0, &attrs2); }), @@ -102,7 +102,7 @@ fn prometheus_exporter_integration() { name: "gauge", expected_file: "gauge.txt", record_metrics: Box::new(|meter| { - let attrs = vec![Key::new("A").string("B"), Key::new("C").string("D")]; + let attrs = vec![KeyValue::new("A", "B"), KeyValue::new("C", "D")]; let gauge = meter .f64_up_down_counter("bar") .with_description("a fun little gauge") @@ -117,7 +117,7 @@ fn prometheus_exporter_integration() { name: "histogram", expected_file: "histogram.txt", record_metrics: Box::new(|meter| { - let attrs = vec![Key::new("A").string("B"), Key::new("C").string("D")]; + let attrs = vec![KeyValue::new("A", "B"), KeyValue::new("C", "D")]; let histogram = meter .f64_histogram("histogram_baz") .with_description("a very nice histogram") @@ -137,11 +137,11 @@ fn prometheus_exporter_integration() { record_metrics: Box::new(|meter| { let attrs = vec![ // exact match, value should be overwritten - Key::new("A.B").string("X"), - Key::new("A.B").string("Q"), + KeyValue::new("A.B", "X"), + KeyValue::new("A.B", "Q"), // unintended match due to sanitization, values should be concatenated - Key::new("C.D").string("Y"), - Key::new("C/D").string("Z"), + KeyValue::new("C.D", "Y"), + KeyValue::new("C/D", "Z"), ]; let counter = meter .f64_counter("foo") @@ -159,7 +159,7 @@ fn prometheus_exporter_integration() { name: "invalid instruments are renamed", expected_file: "sanitized_names.txt", record_metrics: Box::new(|meter| { - let attrs = vec![Key::new("A").string("B"), Key::new("C").string("D")]; + let attrs = vec![KeyValue::new("A", "B"), KeyValue::new("C", "D")]; // Valid. let mut gauge = meter .f64_up_down_counter("bar") @@ -195,10 +195,10 @@ fn prometheus_exporter_integration() { expected_file: "empty_resource.txt", record_metrics: Box::new(|meter| { let attrs = vec![ - Key::new("A").string("B"), - Key::new("C").string("D"), - Key::new("E").bool(true), - Key::new("F").i64(42), + KeyValue::new("A", "B"), + KeyValue::new("C", "D"), + KeyValue::new("E", true), + KeyValue::new("F", 42), ]; let counter = meter .f64_counter("foo") @@ -212,14 +212,14 @@ fn prometheus_exporter_integration() { }, TestCase { name: "custom resource", - custom_resource_attrs: vec![Key::new("A").string("B"), Key::new("C").string("D")], + custom_resource_attrs: vec![KeyValue::new("A", "B"), KeyValue::new("C", "D")], expected_file: "custom_resource.txt", record_metrics: Box::new(|meter| { let attrs = vec![ - Key::new("A").string("B"), - Key::new("C").string("D"), - Key::new("E").bool(true), - Key::new("F").i64(42), + KeyValue::new("A", "B"), + KeyValue::new("C", "D"), + KeyValue::new("E", true), + KeyValue::new("F", 42), ]; let counter = meter .f64_counter("foo") @@ -237,10 +237,10 @@ fn prometheus_exporter_integration() { expected_file: "without_target_info.txt", record_metrics: Box::new(|meter| { let attrs = vec![ - Key::new("A").string("B"), - Key::new("C").string("D"), - Key::new("E").bool(true), - Key::new("F").i64(42), + KeyValue::new("A", "B"), + KeyValue::new("C", "D"), + KeyValue::new("E", true), + KeyValue::new("F", 42), ]; let counter = meter .f64_counter("foo") @@ -257,7 +257,7 @@ fn prometheus_exporter_integration() { builder: ExporterBuilder::default().without_scope_info(), expected_file: "without_scope_info.txt", record_metrics: Box::new(|meter| { - let attrs = vec![Key::new("A").string("B"), Key::new("C").string("D")]; + let attrs = vec![KeyValue::new("A", "B"), KeyValue::new("C", "D")]; let gauge = meter .i64_up_down_counter("bar") .with_description("a fun little gauge") @@ -275,7 +275,7 @@ fn prometheus_exporter_integration() { .without_target_info(), expected_file: "without_scope_and_target_info.txt", record_metrics: Box::new(|meter| { - let attrs = vec![Key::new("A").string("B"), Key::new("C").string("D")]; + let attrs = vec![KeyValue::new("A", "B"), KeyValue::new("C", "D")]; let counter = meter .u64_counter("bar") .with_description("a fun little counter") @@ -292,10 +292,10 @@ fn prometheus_exporter_integration() { expected_file: "with_namespace.txt", record_metrics: Box::new(|meter| { let attrs = vec![ - Key::new("A").string("B"), - Key::new("C").string("D"), - Key::new("E").bool(true), - Key::new("F").i64(42), + KeyValue::new("A", "B"), + KeyValue::new("C", "D"), + KeyValue::new("E", true), + KeyValue::new("F", 42), ]; let counter = meter .f64_counter("foo") @@ -313,7 +313,7 @@ fn prometheus_exporter_integration() { builder: ExporterBuilder::default().with_resource_selector(ResourceSelector::All), expected_file: "resource_in_every_metrics.txt", record_metrics: Box::new(|meter| { - let attrs = vec![Key::new("A").string("B"), Key::new("C").string("D")]; + let attrs = vec![KeyValue::new("A", "B"), KeyValue::new("C", "D")]; let gauge = meter .i64_up_down_counter("bar") .with_description("a fun little gauge") @@ -330,7 +330,7 @@ fn prometheus_exporter_integration() { .with_resource_selector(HashSet::from([Key::new("service.name")])), expected_file: "select_resource_in_every_metrics.txt", record_metrics: Box::new(|meter| { - let attrs = vec![Key::new("A").string("B"), Key::new("C").string("D")]; + let attrs = vec![KeyValue::new("A", "B"), KeyValue::new("C", "D")]; let gauge = meter .i64_up_down_counter("bar") .with_description("a fun little gauge")