Skip to content

Commit d08a861

Browse files
cijothomasTommyCpp
andauthored
[Metric SDK] - Avoid exposing AttributeSet to exporters - Part2 (#1794)
Co-authored-by: Zhongyang Wu <[email protected]>
1 parent 5937065 commit d08a861

File tree

14 files changed

+202
-226
lines changed

14 files changed

+202
-226
lines changed

opentelemetry-sdk/benches/attribute_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use criterion::{criterion_group, criterion_main, Criterion};
22
use opentelemetry::KeyValue;
3-
use opentelemetry_sdk::AttributeSet;
3+
use opentelemetry_sdk::metrics::AttributeSet;
44

55
// Run this benchmark with:
66
// cargo bench --bench attribute_set --features=metrics

opentelemetry-sdk/src/attributes/mod.rs

-3
This file was deleted.

opentelemetry-sdk/src/attributes/set.rs

-184
This file was deleted.

opentelemetry-sdk/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
)]
121121
#![cfg_attr(test, deny(warnings))]
122122

123-
pub(crate) mod attributes;
124123
pub mod export;
125124
mod instrumentation;
126125
#[cfg(feature = "logs")]
@@ -146,7 +145,6 @@ pub mod trace;
146145
#[doc(hidden)]
147146
pub mod util;
148147

149-
pub use attributes::*;
150148
pub use instrumentation::{InstrumentationLibrary, Scope};
151149
#[doc(inline)]
152150
pub use resource::Resource;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{any, borrow::Cow, fmt, time::SystemTime};
44

55
use opentelemetry::{metrics::Unit, KeyValue};
66

7-
use crate::{attributes::AttributeSet, instrumentation::Scope, Resource};
7+
use crate::{instrumentation::Scope, Resource};
88

99
pub use self::temporality::Temporality;
1010

@@ -210,7 +210,7 @@ impl<T: fmt::Debug + Send + Sync + 'static> Aggregation for ExponentialHistogram
210210
#[derive(Debug)]
211211
pub struct ExponentialHistogramDataPoint<T> {
212212
/// The set of key value pairs that uniquely identify the time series.
213-
pub attributes: AttributeSet,
213+
pub attributes: Vec<KeyValue>,
214214
/// When the time series was started.
215215
pub start_time: SystemTime,
216216
/// The time when the time series was recorded.

opentelemetry-sdk/src/metrics/instrument.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use opentelemetry::{
99
};
1010

1111
use crate::{
12-
attributes::AttributeSet,
1312
instrumentation::Scope,
13+
metrics::AttributeSet,
1414
metrics::{aggregation::Aggregation, internal::Measure},
1515
};
1616

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

+4-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use opentelemetry::KeyValue;
55

66
use crate::{
77
metrics::data::{Aggregation, Gauge, Temporality},
8-
AttributeSet,
8+
metrics::AttributeSet,
99
};
1010

1111
use super::{
@@ -217,7 +217,7 @@ mod tests {
217217
DataPoint, ExponentialBucket, ExponentialHistogram, ExponentialHistogramDataPoint,
218218
Histogram, HistogramDataPoint, Sum,
219219
};
220-
use std::time::SystemTime;
220+
use std::{time::SystemTime, vec};
221221

222222
use super::*;
223223

@@ -382,7 +382,7 @@ mod tests {
382382
.exponential_bucket_histogram(4, 20, true, true);
383383
let mut a = ExponentialHistogram {
384384
data_points: vec![ExponentialHistogramDataPoint {
385-
attributes: AttributeSet::from(&[KeyValue::new("a2", 2)][..]),
385+
attributes: vec![KeyValue::new("a1", 1)],
386386
start_time: SystemTime::now(),
387387
time: SystemTime::now(),
388388
count: 2,
@@ -417,10 +417,7 @@ mod tests {
417417
assert!(new_agg.is_none());
418418
assert_eq!(a.temporality, temporality);
419419
assert_eq!(a.data_points.len(), 1);
420-
assert_eq!(
421-
a.data_points[0].attributes,
422-
AttributeSet::from(&new_attributes[..])
423-
);
420+
assert_eq!(a.data_points[0].attributes, new_attributes.to_vec());
424421
assert_eq!(a.data_points[0].count, 1);
425422
assert_eq!(a.data_points[0].min, Some(3));
426423
assert_eq!(a.data_points[0].max, Some(3));

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

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use std::{collections::HashMap, f64::consts::LOG2_E, sync::Mutex, time::SystemTime};
22

33
use once_cell::sync::Lazy;
4-
use opentelemetry::metrics::MetricsError;
4+
use opentelemetry::{metrics::MetricsError, KeyValue};
55

66
use crate::{
77
metrics::data::{self, Aggregation, Temporality},
8-
AttributeSet,
8+
metrics::AttributeSet,
99
};
1010

1111
use super::Number;
@@ -396,7 +396,10 @@ impl<T: Number<T>> ExpoHistogram<T> {
396396

397397
for (a, b) in values.drain() {
398398
h.data_points.push(data::ExponentialHistogramDataPoint {
399-
attributes: a,
399+
attributes: a
400+
.iter()
401+
.map(|(k, v)| KeyValue::new(k.clone(), v.clone()))
402+
.collect(),
400403
start_time: start,
401404
time: t,
402405
count: b.count,
@@ -474,7 +477,10 @@ impl<T: Number<T>> ExpoHistogram<T> {
474477
// overload the system.
475478
for (a, b) in values.iter() {
476479
h.data_points.push(data::ExponentialHistogramDataPoint {
477-
attributes: a.clone(),
480+
attributes: a
481+
.iter()
482+
.map(|(k, v)| KeyValue::new(k.clone(), v.clone()))
483+
.collect(),
478484
start_time: start,
479485
time: t,
480486
count: b.count,
@@ -1260,7 +1266,7 @@ mod tests {
12601266
want: data::ExponentialHistogram {
12611267
temporality: Temporality::Delta,
12621268
data_points: vec![data::ExponentialHistogramDataPoint {
1263-
attributes: AttributeSet::default(),
1269+
attributes: vec![],
12641270
count: 6,
12651271
min: Some(1.into()),
12661272
max: Some(16.into()),
@@ -1303,7 +1309,7 @@ mod tests {
13031309
want: data::ExponentialHistogram {
13041310
temporality: Temporality::Cumulative,
13051311
data_points: vec![data::ExponentialHistogramDataPoint {
1306-
attributes: AttributeSet::default(),
1312+
attributes: vec![],
13071313
count: 6,
13081314
min: Some(1.into()),
13091315
max: Some(16.into()),
@@ -1349,7 +1355,7 @@ mod tests {
13491355
want: data::ExponentialHistogram {
13501356
temporality: Temporality::Delta,
13511357
data_points: vec![data::ExponentialHistogramDataPoint {
1352-
attributes: AttributeSet::default(),
1358+
attributes: vec![],
13531359
count: 6,
13541360
min: Some(1.into()),
13551361
max: Some(16.into()),
@@ -1404,7 +1410,7 @@ mod tests {
14041410
offset: -1,
14051411
counts: vec![1, 6, 2],
14061412
},
1407-
attributes: AttributeSet::default(),
1413+
attributes: vec![],
14081414
start_time: SystemTime::now(),
14091415
time: SystemTime::now(),
14101416
negative_bucket: data::ExponentialBucket {

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

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

33
use crate::metrics::data::{self, Aggregation, Temporality};
4-
use crate::{attributes::AttributeSet, metrics::data::HistogramDataPoint};
4+
use crate::{metrics::data::HistogramDataPoint, metrics::AttributeSet};
55
use opentelemetry::KeyValue;
66
use opentelemetry::{global, metrics::MetricsError};
77

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{
44
time::SystemTime,
55
};
66

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

1010
use super::{

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use std::{
66
time::SystemTime,
77
};
88

9-
use crate::attributes::AttributeSet;
109
use crate::metrics::data::{self, Aggregation, DataPoint, Temporality};
10+
use crate::metrics::AttributeSet;
1111
use opentelemetry::KeyValue;
1212
use opentelemetry::{global, metrics::MetricsError};
1313

0 commit comments

Comments
 (0)