Skip to content

feat: update otel versions for prometheus to 0.26 #2183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Oct 21, 2024
4 changes: 4 additions & 0 deletions opentelemetry-prometheus/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

6 changes: 3 additions & 3 deletions opentelemetry-prometheus/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"] }
24 changes: 1 addition & 23 deletions opentelemetry-prometheus/src/config.rs
Original file line number Diff line number Diff line change
@@ -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<PrometheusExporter> {
let reader = Arc::new(self.reader.build());
10 changes: 2 additions & 8 deletions opentelemetry-prometheus/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<Pipeline>) {
self.reader.register_pipeline(pipeline)
89 changes: 45 additions & 44 deletions opentelemetry-prometheus/tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ use opentelemetry_sdk::Resource;
use opentelemetry_semantic_conventions::resource::{SERVICE_NAME, TELEMETRY_SDK_VERSION};
use prometheus::{Encoder, TextEncoder};

#[ignore = "https://github.com/open-telemetry/opentelemetry-rust/pull/2224"]
#[test]
fn prometheus_exporter_integration() {
struct TestCase {
@@ -46,10 +47,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 +61,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 +76,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 +90,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 +103,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 +118,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 +138,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 +160,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 +196,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 +213,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 +238,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 +258,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 +276,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 +293,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 +314,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 +331,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")