Skip to content

Commit a00f324

Browse files
authored
Merge branch 'main' into cijothomas/log-resource
2 parents 1a7204b + 21bc36c commit a00f324

File tree

11 files changed

+66
-50
lines changed

11 files changed

+66
-50
lines changed

Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ members = [
77
"examples/*",
88
"stress",
99
]
10-
# Any deleted crates with remaining README
11-
exclude = []
1210
resolver = "2"
1311

1412
[profile.bench]

opentelemetry-prometheus/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ rustdoc-args = ["--cfg", "docsrs"]
2121

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

2929
[dev-dependencies]
30-
opentelemetry-semantic-conventions = { path = "../opentelemetry-semantic-conventions" }
30+
opentelemetry-semantic-conventions = { version = "0.15" }
3131
hyper = { workspace = true, features = ["full"] }
3232
tokio = { workspace = true, features = ["full"] }
3333

opentelemetry-prometheus/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
[splash]: https://raw.githubusercontent.com/open-telemetry/opentelemetry-rust/main/assets/logo-text.png
66

7-
[`Prometheus`] integration for applications instrumented with [`OpenTelemetry`].
7+
[`Prometheus`] integration for applications instrumented with [`OpenTelemetry`].
8+
9+
**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**.
811

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

opentelemetry-prometheus/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
//! An OpenTelemetry exporter for [Prometheus] metrics.
22
//!
3+
//! <div class="warning"> The development of prometheus exporter has halt until the Opentelemetry metrics API and SDK reaches 1.0. Current
4+
//! implementation is based on Opentelemetry API and SDK 0.23.</div>
5+
//!
36
//! [Prometheus]: https://prometheus.io
47
//!
58
//! ```
@@ -17,7 +20,7 @@
1720
//! .with_registry(registry.clone())
1821
//! .build()?;
1922
//!
20-
//! // set up a meter meter to create instruments
23+
//! // set up a meter to create instruments
2124
//! let provider = SdkMeterProvider::builder().with_reader(exporter).build();
2225
//! let meter = provider.meter("my-app");
2326
//!

opentelemetry-sdk/src/metrics/data/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl<T: fmt::Debug + Send + Sync + 'static> Aggregation for Sum<T> {
9797
pub struct DataPoint<T> {
9898
/// Attributes is the set of key value pairs that uniquely identify the
9999
/// time series.
100-
pub attributes: AttributeSet,
100+
pub attributes: Vec<KeyValue>,
101101
/// The time when the time series was started.
102102
pub start_time: Option<SystemTime>,
103103
/// The time when the time series was recorded.
@@ -143,7 +143,7 @@ impl<T: fmt::Debug + Send + Sync + 'static> Aggregation for Histogram<T> {
143143
#[derive(Debug)]
144144
pub struct HistogramDataPoint<T> {
145145
/// The set of key value pairs that uniquely identify the time series.
146-
pub attributes: AttributeSet,
146+
pub attributes: Vec<KeyValue>,
147147
/// The time when the time series was started.
148148
pub start_time: SystemTime,
149149
/// The time when the time series was recorded.

opentelemetry-sdk/src/metrics/internal/aggregate.rs

+10-22
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ mod tests {
226226
let (measure, agg) = AggregateBuilder::<u64>::new(None, None).last_value();
227227
let mut a = Gauge {
228228
data_points: vec![DataPoint {
229-
attributes: AttributeSet::from(&[KeyValue::new("a", 1)][..]),
229+
attributes: vec![KeyValue::new("a", 1)],
230230
start_time: Some(SystemTime::now()),
231231
time: Some(SystemTime::now()),
232232
value: 1u64,
@@ -241,10 +241,7 @@ mod tests {
241241
assert_eq!(count, 1);
242242
assert!(new_agg.is_none());
243243
assert_eq!(a.data_points.len(), 1);
244-
assert_eq!(
245-
a.data_points[0].attributes,
246-
AttributeSet::from(&new_attributes[..])
247-
);
244+
assert_eq!(a.data_points[0].attributes, new_attributes.to_vec());
248245
assert_eq!(a.data_points[0].value, 2);
249246
}
250247

@@ -256,14 +253,14 @@ mod tests {
256253
let mut a = Sum {
257254
data_points: vec![
258255
DataPoint {
259-
attributes: AttributeSet::from(&[KeyValue::new("a1", 1)][..]),
256+
attributes: vec![KeyValue::new("a1", 1)],
260257
start_time: Some(SystemTime::now()),
261258
time: Some(SystemTime::now()),
262259
value: 1u64,
263260
exemplars: vec![],
264261
},
265262
DataPoint {
266-
attributes: AttributeSet::from(&[KeyValue::new("a2", 2)][..]),
263+
attributes: vec![KeyValue::new("a2", 1)],
267264
start_time: Some(SystemTime::now()),
268265
time: Some(SystemTime::now()),
269266
value: 2u64,
@@ -287,10 +284,7 @@ mod tests {
287284
assert_eq!(a.temporality, temporality);
288285
assert!(a.is_monotonic);
289286
assert_eq!(a.data_points.len(), 1);
290-
assert_eq!(
291-
a.data_points[0].attributes,
292-
AttributeSet::from(&new_attributes[..])
293-
);
287+
assert_eq!(a.data_points[0].attributes, new_attributes.to_vec());
294288
assert_eq!(a.data_points[0].value, 3);
295289
}
296290
}
@@ -302,14 +296,14 @@ mod tests {
302296
let mut a = Sum {
303297
data_points: vec![
304298
DataPoint {
305-
attributes: AttributeSet::from(&[KeyValue::new("a1", 1)][..]),
299+
attributes: vec![KeyValue::new("a1", 1)],
306300
start_time: Some(SystemTime::now()),
307301
time: Some(SystemTime::now()),
308302
value: 1u64,
309303
exemplars: vec![],
310304
},
311305
DataPoint {
312-
attributes: AttributeSet::from(&[KeyValue::new("a2", 2)][..]),
306+
attributes: vec![KeyValue::new("a2", 1)],
313307
start_time: Some(SystemTime::now()),
314308
time: Some(SystemTime::now()),
315309
value: 2u64,
@@ -333,10 +327,7 @@ mod tests {
333327
assert_eq!(a.temporality, temporality);
334328
assert!(a.is_monotonic);
335329
assert_eq!(a.data_points.len(), 1);
336-
assert_eq!(
337-
a.data_points[0].attributes,
338-
AttributeSet::from(&new_attributes[..])
339-
);
330+
assert_eq!(a.data_points[0].attributes, new_attributes.to_vec());
340331
assert_eq!(a.data_points[0].value, 3);
341332
}
342333
}
@@ -348,7 +339,7 @@ mod tests {
348339
.explicit_bucket_histogram(vec![1.0], true, true);
349340
let mut a = Histogram {
350341
data_points: vec![HistogramDataPoint {
351-
attributes: AttributeSet::from(&[KeyValue::new("a2", 2)][..]),
342+
attributes: vec![KeyValue::new("a1", 1)],
352343
start_time: SystemTime::now(),
353344
time: SystemTime::now(),
354345
count: 2,
@@ -374,10 +365,7 @@ mod tests {
374365
assert!(new_agg.is_none());
375366
assert_eq!(a.temporality, temporality);
376367
assert_eq!(a.data_points.len(), 1);
377-
assert_eq!(
378-
a.data_points[0].attributes,
379-
AttributeSet::from(&new_attributes[..])
380-
);
368+
assert_eq!(a.data_points[0].attributes, new_attributes.to_vec());
381369
assert_eq!(a.data_points[0].count, 1);
382370
assert_eq!(a.data_points[0].bounds, vec![1.0]);
383371
assert_eq!(a.data_points[0].bucket_counts, vec![0, 1]);

opentelemetry-sdk/src/metrics/internal/histogram.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::{collections::HashMap, sync::Mutex, time::SystemTime};
22

33
use crate::metrics::data::{self, Aggregation, Temporality};
44
use crate::{attributes::AttributeSet, metrics::data::HistogramDataPoint};
5+
use opentelemetry::KeyValue;
56
use opentelemetry::{global, metrics::MetricsError};
67

78
use super::{
@@ -165,7 +166,10 @@ impl<T: Number<T>> Histogram<T> {
165166

166167
for (a, b) in values.drain() {
167168
h.data_points.push(HistogramDataPoint {
168-
attributes: a,
169+
attributes: a
170+
.iter()
171+
.map(|(k, v)| KeyValue::new(k.clone(), v.clone()))
172+
.collect(),
169173
start_time: start,
170174
time: t,
171175
count: b.count,
@@ -236,7 +240,10 @@ impl<T: Number<T>> Histogram<T> {
236240
// overload the system.
237241
for (a, b) in values.iter() {
238242
h.data_points.push(HistogramDataPoint {
239-
attributes: a.clone(),
243+
attributes: a
244+
.iter()
245+
.map(|(k, v)| KeyValue::new(k.clone(), v.clone()))
246+
.collect(),
240247
start_time: start,
241248
time: t,
242249
count: b.count,

opentelemetry-sdk/src/metrics/internal/last_value.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{
55
};
66

77
use crate::{attributes::AttributeSet, metrics::data::DataPoint};
8-
use opentelemetry::{global, metrics::MetricsError};
8+
use opentelemetry::{global, metrics::MetricsError, KeyValue};
99

1010
use super::{
1111
aggregate::{is_under_cardinality_limit, STREAM_OVERFLOW_ATTRIBUTE_SET},
@@ -66,7 +66,10 @@ impl<T: Number<T>> LastValue<T> {
6666

6767
for (attrs, value) in values.drain() {
6868
dest.push(DataPoint {
69-
attributes: attrs,
69+
attributes: attrs
70+
.iter()
71+
.map(|(k, v)| KeyValue::new(k.clone(), v.clone()))
72+
.collect(),
7073
time: Some(value.timestamp),
7174
value: value.value,
7275
start_time: None,

opentelemetry-sdk/src/metrics/internal/sum.rs

+22-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::sync::atomic::{AtomicBool, Ordering};
2+
use std::vec;
23
use std::{
34
collections::{hash_map::Entry, HashMap},
45
sync::Mutex,
@@ -7,6 +8,7 @@ use std::{
78

89
use crate::attributes::AttributeSet;
910
use crate::metrics::data::{self, Aggregation, DataPoint, Temporality};
11+
use opentelemetry::KeyValue;
1012
use opentelemetry::{global, metrics::MetricsError};
1113

1214
use super::{
@@ -131,7 +133,7 @@ impl<T: Number<T>> Sum<T> {
131133
.swap(false, Ordering::AcqRel)
132134
{
133135
s_data.data_points.push(DataPoint {
134-
attributes: AttributeSet::default(),
136+
attributes: vec![],
135137
start_time: Some(prev_start),
136138
time: Some(t),
137139
value: self.value_map.no_attribute_value.get_and_reset_value(),
@@ -141,7 +143,10 @@ impl<T: Number<T>> Sum<T> {
141143

142144
for (attrs, value) in values.drain() {
143145
s_data.data_points.push(DataPoint {
144-
attributes: attrs,
146+
attributes: attrs
147+
.iter()
148+
.map(|(k, v)| KeyValue::new(k.clone(), v.clone()))
149+
.collect(),
145150
start_time: Some(prev_start),
146151
time: Some(t),
147152
value,
@@ -201,7 +206,7 @@ impl<T: Number<T>> Sum<T> {
201206
.load(Ordering::Acquire)
202207
{
203208
s_data.data_points.push(DataPoint {
204-
attributes: AttributeSet::default(),
209+
attributes: vec![],
205210
start_time: Some(prev_start),
206211
time: Some(t),
207212
value: self.value_map.no_attribute_value.get_value(),
@@ -215,7 +220,10 @@ impl<T: Number<T>> Sum<T> {
215220
// overload the system.
216221
for (attrs, value) in values.iter() {
217222
s_data.data_points.push(DataPoint {
218-
attributes: attrs.clone(),
223+
attributes: attrs
224+
.iter()
225+
.map(|(k, v)| KeyValue::new(k.clone(), v.clone()))
226+
.collect(),
219227
start_time: Some(prev_start),
220228
time: Some(t),
221229
value: *value,
@@ -297,7 +305,7 @@ impl<T: Number<T>> PrecomputedSum<T> {
297305
.swap(false, Ordering::AcqRel)
298306
{
299307
s_data.data_points.push(DataPoint {
300-
attributes: AttributeSet::default(),
308+
attributes: vec![],
301309
start_time: Some(prev_start),
302310
time: Some(t),
303311
value: self.value_map.no_attribute_value.get_and_reset_value(),
@@ -312,7 +320,10 @@ impl<T: Number<T>> PrecomputedSum<T> {
312320
new_reported.insert(attrs.clone(), value);
313321
}
314322
s_data.data_points.push(DataPoint {
315-
attributes: attrs.clone(),
323+
attributes: attrs
324+
.iter()
325+
.map(|(k, v)| KeyValue::new(k.clone(), v.clone()))
326+
.collect(),
316327
start_time: Some(prev_start),
317328
time: Some(t),
318329
value: delta,
@@ -379,7 +390,7 @@ impl<T: Number<T>> PrecomputedSum<T> {
379390
.load(Ordering::Acquire)
380391
{
381392
s_data.data_points.push(DataPoint {
382-
attributes: AttributeSet::default(),
393+
attributes: vec![],
383394
start_time: Some(prev_start),
384395
time: Some(t),
385396
value: self.value_map.no_attribute_value.get_value(),
@@ -394,7 +405,10 @@ impl<T: Number<T>> PrecomputedSum<T> {
394405
new_reported.insert(attrs.clone(), *value);
395406
}
396407
s_data.data_points.push(DataPoint {
397-
attributes: attrs.clone(),
408+
attributes: attrs
409+
.iter()
410+
.map(|(k, v)| KeyValue::new(k.clone(), v.clone()))
411+
.collect(),
398412
start_time: Some(prev_start),
399413
time: Some(t),
400414
value: delta,

opentelemetry-sdk/src/metrics/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ mod tests {
166166
if datapoint
167167
.attributes
168168
.iter()
169-
.any(|(k, v)| k.as_str() == "key1" && v.as_str() == "value1")
169+
.any(|kv| kv.key.as_str() == "key1" && kv.value.as_str() == "value1")
170170
{
171171
data_point1 = Some(datapoint);
172172
}
@@ -184,7 +184,7 @@ mod tests {
184184
if datapoint
185185
.attributes
186186
.iter()
187-
.any(|(k, v)| k.as_str() == "key1" && v.as_str() == "value2")
187+
.any(|kv| kv.key.as_str() == "key1" && kv.value.as_str() == "value2")
188188
{
189189
data_point1 = Some(datapoint);
190190
}
@@ -1000,7 +1000,7 @@ mod tests {
10001000
datapoint
10011001
.attributes
10021002
.iter()
1003-
.any(|(k, v)| k.as_str() == key && v.as_str() == value)
1003+
.any(|kv| kv.key.as_str() == key && kv.value.as_str() == value)
10041004
})
10051005
}
10061006

opentelemetry-stdout/src/metrics/transform.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl<T: Into<DataValue> + Copy> From<&data::Sum<T>> for Sum {
230230
#[derive(Serialize, Debug, Clone)]
231231
#[serde(rename_all = "camelCase")]
232232
struct DataPoint {
233-
attributes: AttributeSet,
233+
attributes: Vec<KeyValue>,
234234
#[serde(serialize_with = "as_opt_human_readable")]
235235
start_time: Option<SystemTime>,
236236
#[serde(serialize_with = "as_opt_human_readable")]
@@ -253,7 +253,7 @@ fn is_zero_u8(v: &u8) -> bool {
253253
impl<T: Into<DataValue> + Copy> From<&data::DataPoint<T>> for DataPoint {
254254
fn from(value: &data::DataPoint<T>) -> Self {
255255
DataPoint {
256-
attributes: AttributeSet::from(&value.attributes),
256+
attributes: value.attributes.iter().map(Into::into).collect(),
257257
start_time_unix_nano: value.start_time,
258258
time_unix_nano: value.time,
259259
start_time: value.start_time,
@@ -284,7 +284,7 @@ impl<T: Into<DataValue> + Copy> From<&data::Histogram<T>> for Histogram {
284284
#[derive(Serialize, Debug, Clone)]
285285
#[serde(rename_all = "camelCase")]
286286
struct HistogramDataPoint {
287-
attributes: AttributeSet,
287+
attributes: Vec<KeyValue>,
288288
#[serde(serialize_with = "as_unix_nano")]
289289
start_time_unix_nano: SystemTime,
290290
#[serde(serialize_with = "as_unix_nano")]
@@ -306,7 +306,7 @@ struct HistogramDataPoint {
306306
impl<T: Into<DataValue> + Copy> From<&data::HistogramDataPoint<T>> for HistogramDataPoint {
307307
fn from(value: &data::HistogramDataPoint<T>) -> Self {
308308
HistogramDataPoint {
309-
attributes: AttributeSet::from(&value.attributes),
309+
attributes: value.attributes.iter().map(Into::into).collect(),
310310
start_time_unix_nano: value.start_time,
311311
time_unix_nano: value.time,
312312
start_time: value.start_time,

0 commit comments

Comments
 (0)