Skip to content

Commit 383c7d1

Browse files
authored
[opentelemetry-prometheus]: Prepare 0.17.0 release using opentelemetry 0.24 (#1957)
1 parent 2b026d9 commit 383c7d1

File tree

8 files changed

+69
-54
lines changed

8 files changed

+69
-54
lines changed

opentelemetry-prometheus/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
## vNext
44

5+
## v0.17.0
6+
7+
### Changed
8+
9+
- Update `opentelemetry` dependency version to 0.24
10+
- Update `opentelemetry_sdk` dependency version to 0.24
11+
- Update `opentelemetry-semantic-conventions` dependency version to 0.16
12+
513
## v0.16.0
614

715
### Added

opentelemetry-prometheus/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "opentelemetry-prometheus"
3-
version = "0.16.0"
3+
version = "0.17.0"
44
description = "Prometheus exporter for OpenTelemetry"
55
homepage = "https://github.com/open-telemetry/opentelemetry-rust"
66
repository = "https://github.com/open-telemetry/opentelemetry-rust"
@@ -21,13 +21,13 @@ rustdoc-args = ["--cfg", "docsrs"]
2121

2222
[dependencies]
2323
once_cell = { workspace = true }
24-
opentelemetry = { version = "0.23", default-features = false, features = ["metrics"] }
25-
opentelemetry_sdk = { version = "0.23", default-features = false, features = ["metrics"] }
24+
opentelemetry = { version = "0.24", default-features = false, features = ["metrics"] }
25+
opentelemetry_sdk = { version = "0.24", default-features = false, features = ["metrics"] }
2626
prometheus = "0.13"
2727
protobuf = "2.14"
2828

2929
[dev-dependencies]
30-
opentelemetry-semantic-conventions = { version = "0.15" }
30+
opentelemetry-semantic-conventions = { version = "0.16" }
3131
http-body-util = { workspace = true }
3232
hyper = { workspace = true, features = ["full"] }
3333
hyper-util = { workspace = true, features = ["full"] }

opentelemetry-prometheus/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[`Prometheus`] integration for applications instrumented with [`OpenTelemetry`].
88

99
**The development of prometheus exporter has halt until the Opentelemetry metrics API and SDK reaches 1.0. Current
10-
implementation is based on Opentelemetry API and SDK 0.23**.
10+
implementation is based on Opentelemetry API and SDK 0.24**.
1111

1212
[![Crates.io: opentelemetry-prometheus](https://img.shields.io/crates/v/opentelemetry-prometheus.svg)](https://crates.io/crates/opentelemetry-prometheus)
1313
[![Documentation](https://docs.rs/opentelemetry-prometheus/badge.svg)](https://docs.rs/opentelemetry-prometheus)

opentelemetry-prometheus/examples/hyper.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use hyper::{
88
use hyper_util::rt::{TokioExecutor, TokioIo};
99
use once_cell::sync::Lazy;
1010
use opentelemetry::{
11-
metrics::{Counter, Histogram, MeterProvider as _, Unit},
11+
metrics::{Counter, Histogram, MeterProvider as _},
1212
KeyValue,
1313
};
1414
use opentelemetry_sdk::metrics::SdkMeterProvider;
@@ -88,12 +88,12 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
8888
.init(),
8989
http_body_gauge: meter
9090
.u64_histogram("example.http_response_size")
91-
.with_unit(Unit::new("By"))
91+
.with_unit("By")
9292
.with_description("The metrics HTTP response sizes in bytes.")
9393
.init(),
9494
http_req_histogram: meter
9595
.f64_histogram("example.http_request_duration")
96-
.with_unit(Unit::new("ms"))
96+
.with_unit("ms")
9797
.with_description("The HTTP request latencies in milliseconds.")
9898
.init(),
9999
});

opentelemetry-prometheus/src/lib.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,10 @@ fn add_histogram_metric<T: Numeric>(
457457
// See: https://github.com/tikv/rust-prometheus/issues/393
458458

459459
for dp in &histogram.data_points {
460-
let kvs = get_attrs(&mut dp.attributes.iter(), extra);
460+
let kvs = get_attrs(
461+
&mut dp.attributes.iter().map(|kv| (&kv.key, &kv.value)),
462+
extra,
463+
);
461464
let bounds_len = dp.bounds.len();
462465
let (bucket, _) = dp.bounds.iter().enumerate().fold(
463466
(Vec::with_capacity(bounds_len), 0),
@@ -503,7 +506,10 @@ fn add_sum_metric<T: Numeric>(
503506
};
504507

505508
for dp in &sum.data_points {
506-
let kvs = get_attrs(&mut dp.attributes.iter(), extra);
509+
let kvs = get_attrs(
510+
&mut dp.attributes.iter().map(|kv| (&kv.key, &kv.value)),
511+
extra,
512+
);
507513

508514
let mut pm = prometheus::proto::Metric::default();
509515
pm.set_label(protobuf::RepeatedField::from_vec(kvs));
@@ -535,7 +541,10 @@ fn add_gauge_metric<T: Numeric>(
535541
name: Cow<'static, str>,
536542
) {
537543
for dp in &gauge.data_points {
538-
let kvs = get_attrs(&mut dp.attributes.iter(), extra);
544+
let kvs = get_attrs(
545+
&mut dp.attributes.iter().map(|kv| (&kv.key, &kv.value)),
546+
extra,
547+
);
539548

540549
let mut g = prometheus::proto::Gauge::default();
541550
g.set_value(dp.value.as_f64());

opentelemetry-prometheus/src/resource_selector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl ResourceSelector {
3636
ResourceSelector::All => get_attrs(&mut resource.iter(), &[]),
3737
ResourceSelector::None => Vec::new(),
3838
ResourceSelector::KeyAllowList(keys) => {
39-
get_attrs(&mut resource.iter().filter(|(k, _)| keys.contains(k)), &[])
39+
get_attrs(&mut resource.iter().filter(|(k, _)| keys.contains(*k)), &[])
4040
}
4141
}
4242
}

opentelemetry-prometheus/src/utils.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
use opentelemetry::metrics::Unit;
21
use std::borrow::Cow;
32

43
const NON_APPLICABLE_ON_PER_UNIT: [&str; 8] = ["1", "d", "h", "min", "s", "ms", "us", "ns"];
54

6-
pub(crate) fn get_unit_suffixes(unit: &Unit) -> Option<Cow<'static, str>> {
5+
pub(crate) fn get_unit_suffixes(unit: &str) -> Option<Cow<'static, str>> {
76
// no unit return early
8-
if unit.as_str().is_empty() {
7+
if unit.is_empty() {
98
return None;
109
}
1110

1211
// direct match with known units
13-
if let Some(matched) = get_prom_units(unit.as_str()) {
12+
if let Some(matched) = get_prom_units(unit) {
1413
return Some(Cow::Borrowed(matched));
1514
}
1615

@@ -20,7 +19,7 @@ pub(crate) fn get_unit_suffixes(unit: &Unit) -> Option<Cow<'static, str>> {
2019
// e.g
2120
// "test/y" => "per_year"
2221
// "km/s" => "kilometers_per_second"
23-
if let Some((first, second)) = unit.as_str().split_once('/') {
22+
if let Some((first, second)) = unit.split_once('/') {
2423
return match (
2524
NON_APPLICABLE_ON_PER_UNIT.contains(&first),
2625
get_prom_units(first),
@@ -193,9 +192,8 @@ mod tests {
193192
// annotations
194193
("{request}", None),
195194
];
196-
for (unit_str, expected_suffix) in test_cases {
197-
let unit = Unit::new(unit_str);
198-
assert_eq!(get_unit_suffixes(&unit), expected_suffix);
195+
for (unit, expected_suffix) in test_cases {
196+
assert_eq!(get_unit_suffixes(unit), expected_suffix);
199197
}
200198
}
201199
}

0 commit comments

Comments
 (0)