Skip to content

Commit 89e2a64

Browse files
committed
fix histogramdatapoint in sdk
1 parent 2cb2477 commit 89e2a64

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -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

+2-5
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ mod tests {
339339
.explicit_bucket_histogram(vec![1.0], true, true);
340340
let mut a = Histogram {
341341
data_points: vec![HistogramDataPoint {
342-
attributes: AttributeSet::from(&[KeyValue::new("a2", 2)][..]),
342+
attributes: vec![KeyValue::new("a1", 1)],
343343
start_time: SystemTime::now(),
344344
time: SystemTime::now(),
345345
count: 2,
@@ -365,10 +365,7 @@ mod tests {
365365
assert!(new_agg.is_none());
366366
assert_eq!(a.temporality, temporality);
367367
assert_eq!(a.data_points.len(), 1);
368-
assert_eq!(
369-
a.data_points[0].attributes,
370-
AttributeSet::from(&new_attributes[..])
371-
);
368+
assert_eq!(a.data_points[0].attributes, new_attributes.to_vec());
372369
assert_eq!(a.data_points[0].count, 1);
373370
assert_eq!(a.data_points[0].bounds, vec![1.0]);
374371
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,

0 commit comments

Comments
 (0)