Skip to content

Commit b352c1a

Browse files
committed
fix attributes
1 parent 4049eb3 commit b352c1a

File tree

4 files changed

+47
-15
lines changed

4 files changed

+47
-15
lines changed

opentelemetry-proto/src/transform/metrics.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ pub mod tonic {
210210
data_points: hist
211211
.data_points()
212212
.map(|dp| TonicHistogramDataPoint {
213-
attributes: dp.attributes.iter().map(Into::into).collect(),
213+
attributes: dp.attributes().map(Into::into).collect(),
214214
start_time_unix_nano: to_nanos(hist.start_time),
215215
time_unix_nano: to_nanos(hist.time),
216216
count: dp.count,
@@ -237,7 +237,7 @@ pub mod tonic {
237237
data_points: hist
238238
.data_points()
239239
.map(|dp| TonicExponentialHistogramDataPoint {
240-
attributes: dp.attributes.iter().map(Into::into).collect(),
240+
attributes: dp.attributes().map(Into::into).collect(),
241241
start_time_unix_nano: to_nanos(hist.start_time),
242242
time_unix_nano: to_nanos(hist.time),
243243
count: dp.count as u64,
@@ -273,7 +273,7 @@ pub mod tonic {
273273
data_points: sum
274274
.data_points()
275275
.map(|dp| TonicNumberDataPoint {
276-
attributes: dp.attributes.iter().map(Into::into).collect(),
276+
attributes: dp.attributes().map(Into::into).collect(),
277277
start_time_unix_nano: to_nanos(sum.start_time),
278278
time_unix_nano: to_nanos(sum.time),
279279
exemplars: dp.exemplars.iter().map(Into::into).collect(),
@@ -296,7 +296,7 @@ pub mod tonic {
296296
data_points: gauge
297297
.data_points()
298298
.map(|dp| TonicNumberDataPoint {
299-
attributes: dp.attributes.iter().map(Into::into).collect(),
299+
attributes: dp.attributes().map(Into::into).collect(),
300300
start_time_unix_nano: gauge.start_time.map(to_nanos).unwrap_or_default(),
301301
time_unix_nano: to_nanos(gauge.time),
302302
exemplars: dp.exemplars.iter().map(Into::into).collect(),

opentelemetry-sdk/CHANGELOG.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,16 @@ also modified to suppress telemetry before invoking exporters.
4747
- *Breaking* change, affecting custom `PushMetricExporter` authors:
4848
- The `export` method on `PushMetricExporter` now accepts `&ResourceMetrics`
4949
instead of `&mut ResourceMetrics`.
50-
- `ResourceMetrics` no longer exposes `scope_metrics` field, but instead offers
51-
`scope_metrics()` method that returns an iterator over the same.
50+
- `ResourceMetrics` no longer exposes `scope_metrics` field, but instead
51+
offers `scope_metrics()` method that returns an iterator over the same.
5252
- `ScopeMetrics` no longer exposes `metrics` field, but instead offers
5353
`metrics()` method that returns an iterator over the same.
54-
- `Sum`, `Gauge` no longer exposes `data_points` field, but instead offers
55-
`data_points()` method that returns an iterator over the same.
54+
- `Sum`, `Gauge`, `Histogram` & `ExponentialHistogram` no longer exposes
55+
`data_points` field, but instead offers `data_points()` method that returns
56+
an iterator over the same.
57+
- `SumDataPoint`, `GaugeDataPoint`, `HistogramDataPoint` &
58+
`ExponentialHistogramDataPoint` no longer exposes `attributes` field, but
59+
instead offers `attributes()` method that returns an iterator over the same.
5660

5761
## 0.29.0
5862

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

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,20 @@ impl<T> From<ExponentialHistogram<T>> for MetricData<T> {
135135
pub struct GaugeDataPoint<T> {
136136
/// Attributes is the set of key value pairs that uniquely identify the
137137
/// time series.
138-
pub attributes: Vec<KeyValue>,
138+
pub(crate) attributes: Vec<KeyValue>,
139139
/// The value of this data point.
140140
pub value: T,
141141
/// The sampled [Exemplar]s collected during the time series.
142142
pub exemplars: Vec<Exemplar<T>>,
143143
}
144144

145+
impl<T> GaugeDataPoint<T> {
146+
/// Returns an iterator over the attributes in [GaugeDataPoint].
147+
pub fn attributes(&self) -> impl Iterator<Item = &KeyValue> {
148+
self.attributes.iter()
149+
}
150+
}
151+
145152
/// A measurement of the current value of an instrument.
146153
#[derive(Debug, Clone)]
147154
pub struct Gauge<T> {
@@ -165,13 +172,20 @@ impl<T> Gauge<T> {
165172
pub struct SumDataPoint<T> {
166173
/// Attributes is the set of key value pairs that uniquely identify the
167174
/// time series.
168-
pub attributes: Vec<KeyValue>,
175+
pub(crate) attributes: Vec<KeyValue>,
169176
/// The value of this data point.
170177
pub value: T,
171178
/// The sampled [Exemplar]s collected during the time series.
172179
pub exemplars: Vec<Exemplar<T>>,
173180
}
174181

182+
impl<T> SumDataPoint<T> {
183+
/// Returns an iterator over the attributes in [SumDataPoint].
184+
pub fn attributes(&self) -> impl Iterator<Item = &KeyValue> {
185+
self.attributes.iter()
186+
}
187+
}
188+
175189
/// Represents the sum of all measurements of values from an instrument.
176190
#[derive(Debug, Clone)]
177191
pub struct Sum<T> {
@@ -220,7 +234,7 @@ impl<T> Histogram<T> {
220234
#[derive(Debug, Clone, PartialEq)]
221235
pub struct HistogramDataPoint<T> {
222236
/// The set of key value pairs that uniquely identify the time series.
223-
pub attributes: Vec<KeyValue>,
237+
pub(crate) attributes: Vec<KeyValue>,
224238
/// The number of updates this histogram has been calculated with.
225239
pub count: u64,
226240
/// The upper bounds of the buckets of the histogram.
@@ -241,6 +255,13 @@ pub struct HistogramDataPoint<T> {
241255
pub exemplars: Vec<Exemplar<T>>,
242256
}
243257

258+
impl<T> HistogramDataPoint<T> {
259+
/// Returns an iterator over the attributes in [HistogramDataPoint].
260+
pub fn attributes(&self) -> impl Iterator<Item = &KeyValue> {
261+
self.attributes.iter()
262+
}
263+
}
264+
244265
/// The histogram of all measurements of values from an instrument.
245266
#[derive(Debug, Clone)]
246267
pub struct ExponentialHistogram<T> {
@@ -266,7 +287,7 @@ impl<T> ExponentialHistogram<T> {
266287
#[derive(Debug, Clone, PartialEq)]
267288
pub struct ExponentialHistogramDataPoint<T> {
268289
/// The set of key value pairs that uniquely identify the time series.
269-
pub attributes: Vec<KeyValue>,
290+
pub(crate) attributes: Vec<KeyValue>,
270291

271292
/// The number of updates this histogram has been calculated with.
272293
pub count: usize,
@@ -307,6 +328,13 @@ pub struct ExponentialHistogramDataPoint<T> {
307328
pub exemplars: Vec<Exemplar<T>>,
308329
}
309330

331+
impl<T> ExponentialHistogramDataPoint<T> {
332+
/// Returns an iterator over the attributes in [ExponentialHistogramDataPoint].
333+
pub fn attributes(&self) -> impl Iterator<Item = &KeyValue> {
334+
self.attributes.iter()
335+
}
336+
}
337+
310338
/// A set of bucket counts, encoded in a contiguous array of counts.
311339
#[derive(Debug, Clone, PartialEq)]
312340
pub struct ExponentialBucket {

opentelemetry-stdout/src/metrics/exporter.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ fn print_sum_data_points<'a, T: Debug + 'a>(
203203
println!("\t\tDataPoint #{}", i);
204204
println!("\t\t\tValue : {:#?}", data_point.value);
205205
println!("\t\t\tAttributes :");
206-
for kv in data_point.attributes.iter() {
206+
for kv in data_point.attributes() {
207207
println!("\t\t\t\t -> {}: {}", kv.key, kv.value.as_str());
208208
}
209209
}
@@ -216,7 +216,7 @@ fn print_gauge_data_points<'a, T: Debug + 'a>(
216216
println!("\t\tDataPoint #{}", i);
217217
println!("\t\t\tValue : {:#?}", data_point.value);
218218
println!("\t\t\tAttributes :");
219-
for kv in data_point.attributes.iter() {
219+
for kv in data_point.attributes() {
220220
println!("\t\t\t\t -> {}: {}", kv.key, kv.value.as_str());
221221
}
222222
}
@@ -238,7 +238,7 @@ fn print_hist_data_points<'a, T: Debug + 'a>(
238238
}
239239

240240
println!("\t\t\tAttributes :");
241-
for kv in data_point.attributes.iter() {
241+
for kv in data_point.attributes() {
242242
println!("\t\t\t\t -> {}: {}", kv.key, kv.value.as_str());
243243
}
244244

0 commit comments

Comments
 (0)