Skip to content

[Metric SDK] - Avoid exposing AttributeSet to exporters - Part2 #1794

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 6 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion opentelemetry-sdk/benches/attribute_set.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use criterion::{criterion_group, criterion_main, Criterion};
use opentelemetry::KeyValue;
use opentelemetry_sdk::AttributeSet;
use opentelemetry_sdk::metrics::AttributeSet;

// Run this benchmark with:
// cargo bench --bench attribute_set --features=metrics
Expand Down
3 changes: 0 additions & 3 deletions opentelemetry-sdk/src/attributes/mod.rs

This file was deleted.

184 changes: 0 additions & 184 deletions opentelemetry-sdk/src/attributes/set.rs

This file was deleted.

2 changes: 0 additions & 2 deletions opentelemetry-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
)]
#![cfg_attr(test, deny(warnings))]

pub(crate) mod attributes;
pub mod export;
mod instrumentation;
#[cfg(feature = "logs")]
Expand All @@ -146,7 +145,6 @@ pub mod trace;
#[doc(hidden)]
pub mod util;

pub use attributes::*;
pub use instrumentation::{InstrumentationLibrary, Scope};
#[doc(inline)]
pub use resource::Resource;
4 changes: 2 additions & 2 deletions opentelemetry-sdk/src/metrics/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{any, borrow::Cow, fmt, time::SystemTime};

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

use crate::{attributes::AttributeSet, instrumentation::Scope, Resource};
use crate::{instrumentation::Scope, Resource};

pub use self::temporality::Temporality;

Expand Down Expand Up @@ -210,7 +210,7 @@ impl<T: fmt::Debug + Send + Sync + 'static> Aggregation for ExponentialHistogram
#[derive(Debug)]
pub struct ExponentialHistogramDataPoint<T> {
/// The set of key value pairs that uniquely identify the time series.
pub attributes: AttributeSet,
pub attributes: Vec<KeyValue>,
/// When the time series was started.
pub start_time: SystemTime,
/// The time when the time series was recorded.
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/metrics/instrument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use opentelemetry::{
};

use crate::{
attributes::AttributeSet,
instrumentation::Scope,
metrics::AttributeSet,
metrics::{aggregation::Aggregation, internal::Measure},
};

Expand Down
11 changes: 4 additions & 7 deletions opentelemetry-sdk/src/metrics/internal/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use opentelemetry::KeyValue;

use crate::{
metrics::data::{Aggregation, Gauge, Temporality},
AttributeSet,
metrics::AttributeSet,
};

use super::{
Expand Down Expand Up @@ -217,7 +217,7 @@ mod tests {
DataPoint, ExponentialBucket, ExponentialHistogram, ExponentialHistogramDataPoint,
Histogram, HistogramDataPoint, Sum,
};
use std::time::SystemTime;
use std::{time::SystemTime, vec};

use super::*;

Expand Down Expand Up @@ -382,7 +382,7 @@ mod tests {
.exponential_bucket_histogram(4, 20, true, true);
let mut a = ExponentialHistogram {
data_points: vec![ExponentialHistogramDataPoint {
attributes: AttributeSet::from(&[KeyValue::new("a2", 2)][..]),
attributes: vec![KeyValue::new("a1", 1)],
start_time: SystemTime::now(),
time: SystemTime::now(),
count: 2,
Expand Down Expand Up @@ -417,10 +417,7 @@ mod tests {
assert!(new_agg.is_none());
assert_eq!(a.temporality, temporality);
assert_eq!(a.data_points.len(), 1);
assert_eq!(
a.data_points[0].attributes,
AttributeSet::from(&new_attributes[..])
);
assert_eq!(a.data_points[0].attributes, new_attributes.to_vec());
assert_eq!(a.data_points[0].count, 1);
assert_eq!(a.data_points[0].min, Some(3));
assert_eq!(a.data_points[0].max, Some(3));
Expand Down
22 changes: 14 additions & 8 deletions opentelemetry-sdk/src/metrics/internal/exponential_histogram.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::{collections::HashMap, f64::consts::LOG2_E, sync::Mutex, time::SystemTime};

use once_cell::sync::Lazy;
use opentelemetry::metrics::MetricsError;
use opentelemetry::{metrics::MetricsError, KeyValue};

use crate::{
metrics::data::{self, Aggregation, Temporality},
AttributeSet,
metrics::AttributeSet,
};

use super::Number;
Expand Down Expand Up @@ -396,7 +396,10 @@ impl<T: Number<T>> ExpoHistogram<T> {

for (a, b) in values.drain() {
h.data_points.push(data::ExponentialHistogramDataPoint {
attributes: a,
attributes: a
.iter()
.map(|(k, v)| KeyValue::new(k.clone(), v.clone()))
.collect(),
start_time: start,
time: t,
count: b.count,
Expand Down Expand Up @@ -474,7 +477,10 @@ impl<T: Number<T>> ExpoHistogram<T> {
// overload the system.
for (a, b) in values.iter() {
h.data_points.push(data::ExponentialHistogramDataPoint {
attributes: a.clone(),
attributes: a
.iter()
.map(|(k, v)| KeyValue::new(k.clone(), v.clone()))
.collect(),
start_time: start,
time: t,
count: b.count,
Expand Down Expand Up @@ -1260,7 +1266,7 @@ mod tests {
want: data::ExponentialHistogram {
temporality: Temporality::Delta,
data_points: vec![data::ExponentialHistogramDataPoint {
attributes: AttributeSet::default(),
attributes: vec![],
count: 6,
min: Some(1.into()),
max: Some(16.into()),
Expand Down Expand Up @@ -1303,7 +1309,7 @@ mod tests {
want: data::ExponentialHistogram {
temporality: Temporality::Cumulative,
data_points: vec![data::ExponentialHistogramDataPoint {
attributes: AttributeSet::default(),
attributes: vec![],
count: 6,
min: Some(1.into()),
max: Some(16.into()),
Expand Down Expand Up @@ -1349,7 +1355,7 @@ mod tests {
want: data::ExponentialHistogram {
temporality: Temporality::Delta,
data_points: vec![data::ExponentialHistogramDataPoint {
attributes: AttributeSet::default(),
attributes: vec![],
count: 6,
min: Some(1.into()),
max: Some(16.into()),
Expand Down Expand Up @@ -1404,7 +1410,7 @@ mod tests {
offset: -1,
counts: vec![1, 6, 2],
},
attributes: AttributeSet::default(),
attributes: vec![],
start_time: SystemTime::now(),
time: SystemTime::now(),
negative_bucket: data::ExponentialBucket {
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/metrics/internal/histogram.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::HashMap, sync::Mutex, time::SystemTime};

use crate::metrics::data::{self, Aggregation, Temporality};
use crate::{attributes::AttributeSet, metrics::data::HistogramDataPoint};
use crate::{metrics::data::HistogramDataPoint, metrics::AttributeSet};
use opentelemetry::KeyValue;
use opentelemetry::{global, metrics::MetricsError};

Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/metrics/internal/last_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
time::SystemTime,
};

use crate::{attributes::AttributeSet, metrics::data::DataPoint};
use crate::{metrics::data::DataPoint, metrics::AttributeSet};
use opentelemetry::{global, metrics::MetricsError, KeyValue};

use super::{
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/metrics/internal/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::{
time::SystemTime,
};

use crate::attributes::AttributeSet;
use crate::metrics::data::{self, Aggregation, DataPoint, Temporality};
use crate::metrics::AttributeSet;
use opentelemetry::KeyValue;
use opentelemetry::{global, metrics::MetricsError};

Expand Down
Loading
Loading