Skip to content

Commit aa20cab

Browse files
authored
Merge branch 'main' into build-profiles
2 parents a993088 + cc93ead commit aa20cab

File tree

8 files changed

+308
-60
lines changed

8 files changed

+308
-60
lines changed

opentelemetry-proto/src/transform/metrics.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,13 @@ pub mod tonic {
114114
fn from(rm: &ResourceMetrics) -> Self {
115115
ExportMetricsServiceRequest {
116116
resource_metrics: vec![TonicResourceMetrics {
117-
resource: Some((&rm.resource).into()),
117+
resource: Some((rm.resource()).into()),
118118
scope_metrics: rm.scope_metrics().map(Into::into).collect(),
119-
schema_url: rm.resource.schema_url().map(Into::into).unwrap_or_default(),
119+
schema_url: rm
120+
.resource()
121+
.schema_url()
122+
.map(Into::into)
123+
.unwrap_or_default(),
120124
}],
121125
}
122126
}
@@ -135,10 +139,10 @@ pub mod tonic {
135139
impl From<&SdkScopeMetrics> for TonicScopeMetrics {
136140
fn from(sm: &SdkScopeMetrics) -> Self {
137141
TonicScopeMetrics {
138-
scope: Some((&sm.scope, None).into()),
142+
scope: Some((sm.scope(), None).into()),
139143
metrics: sm.metrics().map(Into::into).collect(),
140144
schema_url: sm
141-
.scope
145+
.scope()
142146
.schema_url()
143147
.map(ToOwned::to_owned)
144148
.unwrap_or_default(),
@@ -149,11 +153,11 @@ pub mod tonic {
149153
impl From<&SdkMetric> for TonicMetric {
150154
fn from(metric: &SdkMetric) -> Self {
151155
TonicMetric {
152-
name: metric.name.to_string(),
153-
description: metric.description.to_string(),
154-
unit: metric.unit.to_string(),
156+
name: metric.name().to_string(),
157+
description: metric.description().to_string(),
158+
unit: metric.unit().to_string(),
155159
metadata: vec![], // internal and currently unused
156-
data: Some(match &metric.data {
160+
data: Some(match metric.data() {
157161
AggregatedMetrics::F64(data) => data.into(),
158162
AggregatedMetrics::U64(data) => data.into(),
159163
AggregatedMetrics::I64(data) => data.into(),

opentelemetry-sdk/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ also modified to suppress telemetry before invoking exporters.
4242
behind feature flag "experimental_metrics_custom_reader".
4343
[#2928](https://github.com/open-telemetry/opentelemetry-rust/pull/2928)
4444

45+
- TODO: Placeholder for View related changelog. Polish this after all
46+
changes are done.
47+
Hide public fields from `Stream` struct.
48+
4549
- *Breaking* `Aggregation` enum moved behind feature flag
4650
"spec_unstable_metrics_views". This was only required when using Views.
4751
[#2928](https://github.com/open-telemetry/opentelemetry-rust/pull/2928)
@@ -65,6 +69,12 @@ also modified to suppress telemetry before invoking exporters.
6569
- `HistogramDataPoint` no longer exposes `bounds` and `bucket_counts`, but
6670
instead offers `bounds()` and `bucket_counts()` methods that returns an
6771
iterator over the same.
72+
- `Metric` no longer exposes `name`, `description`, `unit`, `data` fields, but
73+
instead offers `name()`, `description()`, `unit()`, and `data()` accessor methods.
74+
- `ResourceMetrics` no longer exposes `resource` field, but instead offers
75+
a `resource()` accessor method.
76+
- `ScopeMetrics` no longer exposes `scope` field, but instead offers
77+
a `scope()` accessor method.
6878

6979
## 0.29.0
7080

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

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use super::Temporality;
1212
#[derive(Debug)]
1313
pub struct ResourceMetrics {
1414
/// The entity that collected the metrics.
15-
pub resource: Resource,
15+
pub(crate) resource: Resource,
1616
/// The collection of metrics with unique [InstrumentationScope]s.
1717
pub(crate) scope_metrics: Vec<ScopeMetrics>,
1818
}
@@ -27,6 +27,11 @@ impl Default for ResourceMetrics {
2727
}
2828

2929
impl ResourceMetrics {
30+
/// Returns a reference to the [Resource] in [ResourceMetrics].
31+
pub fn resource(&self) -> &Resource {
32+
&self.resource
33+
}
34+
3035
/// Returns an iterator over the [ScopeMetrics] in [ResourceMetrics].
3136
pub fn scope_metrics(&self) -> impl Iterator<Item = &ScopeMetrics> {
3237
self.scope_metrics.iter()
@@ -37,12 +42,17 @@ impl ResourceMetrics {
3742
#[derive(Default, Debug)]
3843
pub struct ScopeMetrics {
3944
/// The [InstrumentationScope] that the meter was created with.
40-
pub scope: InstrumentationScope,
45+
pub(crate) scope: InstrumentationScope,
4146
/// The list of aggregations created by the meter.
4247
pub(crate) metrics: Vec<Metric>,
4348
}
4449

4550
impl ScopeMetrics {
51+
/// Returns a reference to the [InstrumentationScope] in [ScopeMetrics].
52+
pub fn scope(&self) -> &InstrumentationScope {
53+
&self.scope
54+
}
55+
4656
/// Returns an iterator over the [Metric]s in [ScopeMetrics].
4757
pub fn metrics(&self) -> impl Iterator<Item = &Metric> {
4858
self.metrics.iter()
@@ -55,13 +65,35 @@ impl ScopeMetrics {
5565
#[derive(Debug)]
5666
pub struct Metric {
5767
/// The name of the instrument that created this data.
58-
pub name: Cow<'static, str>,
68+
pub(crate) name: Cow<'static, str>,
5969
/// The description of the instrument, which can be used in documentation.
60-
pub description: Cow<'static, str>,
70+
pub(crate) description: Cow<'static, str>,
6171
/// The unit in which the instrument reports.
62-
pub unit: Cow<'static, str>,
72+
pub(crate) unit: Cow<'static, str>,
6373
/// The aggregated data from an instrument.
64-
pub data: AggregatedMetrics,
74+
pub(crate) data: AggregatedMetrics,
75+
}
76+
77+
impl Metric {
78+
/// Returns the name of the instrument that created this data.
79+
pub fn name(&self) -> &str {
80+
&self.name
81+
}
82+
83+
/// Returns the description of the instrument.
84+
pub fn description(&self) -> &str {
85+
&self.description
86+
}
87+
88+
/// Returns the unit in which the instrument reports.
89+
pub fn unit(&self) -> &str {
90+
&self.unit
91+
}
92+
93+
/// Returns the aggregated data from the instrument.
94+
pub fn data(&self) -> &AggregatedMetrics {
95+
&self.data
96+
}
6597
}
6698

6799
/// Aggregated metrics data from an instrument

opentelemetry-sdk/src/metrics/instrument.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,22 +190,22 @@ impl Instrument {
190190
#[allow(unreachable_pub)]
191191
pub struct Stream {
192192
/// The human-readable identifier of the stream.
193-
pub name: Cow<'static, str>,
193+
pub(crate) name: Option<Cow<'static, str>>,
194194
/// Describes the purpose of the data.
195-
pub description: Cow<'static, str>,
195+
pub(crate) description: Option<Cow<'static, str>>,
196196
/// the unit of measurement recorded.
197-
pub unit: Cow<'static, str>,
197+
pub(crate) unit: Option<Cow<'static, str>>,
198198
/// Aggregation the stream uses for an instrument.
199-
pub aggregation: Option<Aggregation>,
199+
pub(crate) aggregation: Option<Aggregation>,
200200
/// An allow-list of attribute keys that will be preserved for the stream.
201201
///
202202
/// Any attribute recorded for the stream with a key not in this set will be
203203
/// dropped. If the set is empty, all attributes will be dropped, if `None` all
204204
/// attributes will be kept.
205-
pub allowed_attribute_keys: Option<Arc<HashSet<Key>>>,
205+
pub(crate) allowed_attribute_keys: Option<Arc<HashSet<Key>>>,
206206

207207
/// Cardinality limit for the stream.
208-
pub cardinality_limit: Option<usize>,
208+
pub(crate) cardinality_limit: Option<usize>,
209209
}
210210

211211
#[cfg(feature = "spec_unstable_metrics_views")]
@@ -217,19 +217,19 @@ impl Stream {
217217

218218
/// Set the stream name.
219219
pub fn name(mut self, name: impl Into<Cow<'static, str>>) -> Self {
220-
self.name = name.into();
220+
self.name = Some(name.into());
221221
self
222222
}
223223

224224
/// Set the stream description.
225225
pub fn description(mut self, description: impl Into<Cow<'static, str>>) -> Self {
226-
self.description = description.into();
226+
self.description = Some(description.into());
227227
self
228228
}
229229

230230
/// Set the stream unit.
231231
pub fn unit(mut self, unit: impl Into<Cow<'static, str>>) -> Self {
232-
self.unit = unit.into();
232+
self.unit = Some(unit.into());
233233
self
234234
}
235235

0 commit comments

Comments
 (0)