Skip to content

Commit c60a178

Browse files
authored
Use consistent style of passing attributes to metrics (#1518)
1 parent d7c9ef0 commit c60a178

File tree

4 files changed

+51
-63
lines changed

4 files changed

+51
-63
lines changed

examples/metrics-advanced/src/main.rs

+10-15
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,12 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
8080
// Record measurements using the histogram instrument.
8181
histogram.record(
8282
10.5,
83-
[
83+
&[
8484
KeyValue::new("mykey1", "myvalue1"),
8585
KeyValue::new("mykey2", "myvalue2"),
8686
KeyValue::new("mykey3", "myvalue3"),
8787
KeyValue::new("mykey4", "myvalue4"),
88-
]
89-
.as_ref(),
88+
],
9089
);
9190

9291
// Example 2 - Drop unwanted attributes using view.
@@ -98,13 +97,12 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
9897
// attribute.
9998
counter.add(
10099
10,
101-
[
100+
&[
102101
KeyValue::new("mykey1", "myvalue1"),
103102
KeyValue::new("mykey2", "myvalue2"),
104103
KeyValue::new("mykey3", "myvalue3"),
105104
KeyValue::new("mykey4", "myvalue4"),
106-
]
107-
.as_ref(),
105+
],
108106
);
109107

110108
// Example 3 - Change Aggregation configuration using View.
@@ -122,35 +120,32 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
122120
// the change of boundaries.
123121
histogram2.record(
124122
1.5,
125-
[
123+
&[
126124
KeyValue::new("mykey1", "myvalue1"),
127125
KeyValue::new("mykey2", "myvalue2"),
128126
KeyValue::new("mykey3", "myvalue3"),
129127
KeyValue::new("mykey4", "myvalue4"),
130-
]
131-
.as_ref(),
128+
],
132129
);
133130

134131
histogram2.record(
135132
1.2,
136-
[
133+
&[
137134
KeyValue::new("mykey1", "myvalue1"),
138135
KeyValue::new("mykey2", "myvalue2"),
139136
KeyValue::new("mykey3", "myvalue3"),
140137
KeyValue::new("mykey4", "myvalue4"),
141-
]
142-
.as_ref(),
138+
],
143139
);
144140

145141
histogram2.record(
146142
1.23,
147-
[
143+
&[
148144
KeyValue::new("mykey1", "myvalue1"),
149145
KeyValue::new("mykey2", "myvalue2"),
150146
KeyValue::new("mykey3", "myvalue3"),
151147
KeyValue::new("mykey4", "myvalue4"),
152-
]
153-
.as_ref(),
148+
],
154149
);
155150

156151
// Metrics are exported by default every 30 seconds when using stdout exporter,

examples/metrics-basic/src/main.rs

+14-21
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
3434
// Record measurements using the Counter instrument.
3535
counter.add(
3636
10,
37-
[
37+
&[
3838
KeyValue::new("mykey1", "myvalue1"),
3939
KeyValue::new("mykey2", "myvalue2"),
40-
]
41-
.as_ref(),
40+
],
4241
);
4342

4443
// Create a ObservableCounter instrument and register a callback that reports the measurement.
@@ -52,11 +51,10 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
5251
observer.observe_u64(
5352
&observable_counter,
5453
100,
55-
[
54+
&[
5655
KeyValue::new("mykey1", "myvalue1"),
5756
KeyValue::new("mykey2", "myvalue2"),
58-
]
59-
.as_ref(),
57+
],
6058
)
6159
})?;
6260

@@ -66,11 +64,10 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
6664
// Record measurements using the UpCounter instrument.
6765
updown_counter.add(
6866
-10,
69-
[
67+
&[
7068
KeyValue::new("mykey1", "myvalue1"),
7169
KeyValue::new("mykey2", "myvalue2"),
72-
]
73-
.as_ref(),
70+
],
7471
);
7572

7673
// Create a Observable UpDownCounter instrument and register a callback that reports the measurement.
@@ -84,11 +81,10 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
8481
observer.observe_i64(
8582
&observable_up_down_counter,
8683
100,
87-
[
84+
&[
8885
KeyValue::new("mykey1", "myvalue1"),
8986
KeyValue::new("mykey2", "myvalue2"),
90-
]
91-
.as_ref(),
87+
],
9288
)
9389
})?;
9490

@@ -101,11 +97,10 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
10197
// Record measurements using the histogram instrument.
10298
histogram.record(
10399
10.5,
104-
[
100+
&[
105101
KeyValue::new("mykey1", "myvalue1"),
106102
KeyValue::new("mykey2", "myvalue2"),
107-
]
108-
.as_ref(),
103+
],
109104
);
110105

111106
// Note that there is no ObservableHistogram instrument.
@@ -122,11 +117,10 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
122117

123118
gauge.record(
124119
1.0,
125-
[
120+
&[
126121
KeyValue::new("mykey1", "myvalue1"),
127122
KeyValue::new("mykey2", "myvalue2"),
128-
]
129-
.as_ref(),
123+
],
130124
);
131125
}
132126

@@ -142,11 +136,10 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
142136
observer.observe_f64(
143137
&observable_gauge,
144138
1.0,
145-
[
139+
&[
146140
KeyValue::new("mykey1", "myvalue1"),
147141
KeyValue::new("mykey2", "myvalue2"),
148-
]
149-
.as_ref(),
142+
],
150143
)
151144
})?;
152145

opentelemetry-otlp/tests/integration_test/src/asserter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl TraceAsserter {
1919
self.assert_resource_span_eq(&self.results, &self.expected);
2020
}
2121

22-
fn assert_resource_span_eq(&self, results: &Vec<ResourceSpans>, expected: &Vec<ResourceSpans>) {
22+
fn assert_resource_span_eq(&self, results: &[ResourceSpans], expected: &[ResourceSpans]) {
2323
let mut results_spans = Vec::new();
2424
let mut expected_spans = Vec::new();
2525

opentelemetry/src/metrics/meter.rs

+26-26
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ pub trait MeterProvider {
8383
/// // Record measurements using the counter instrument add()
8484
/// u64_counter.add(
8585
/// 10,
86-
/// [
86+
/// &[
8787
/// KeyValue::new("mykey1", "myvalue1"),
8888
/// KeyValue::new("mykey2", "myvalue2"),
89-
/// ].as_ref()
89+
/// ]
9090
/// );
9191
///
9292
/// // f64 Counter
@@ -95,10 +95,10 @@ pub trait MeterProvider {
9595
/// // Record measurements using the counter instrument add()
9696
/// f64_counter.add(
9797
/// 3.15,
98-
/// [
98+
/// &[
9999
/// KeyValue::new("mykey1", "myvalue1"),
100100
/// KeyValue::new("mykey2", "myvalue2"),
101-
/// ].as_ref()
101+
/// ],
102102
/// );
103103
///
104104
/// // u6 observable counter
@@ -109,10 +109,10 @@ pub trait MeterProvider {
109109
/// observer.observe_u64(
110110
/// &observable_u4_counter,
111111
/// 1,
112-
/// [
112+
/// &[
113113
/// KeyValue::new("mykey1", "myvalue1"),
114114
/// KeyValue::new("mykey2", "myvalue2"),
115-
/// ].as_ref(),
115+
/// ],
116116
/// )
117117
/// });
118118
///
@@ -124,10 +124,10 @@ pub trait MeterProvider {
124124
/// observer.observe_f64(
125125
/// &observable_f64_counter,
126126
/// 1.55,
127-
/// [
127+
/// &[
128128
/// KeyValue::new("mykey1", "myvalue1"),
129129
/// KeyValue::new("mykey2", "myvalue2"),
130-
/// ].as_ref(),
130+
/// ],
131131
/// )
132132
/// });
133133
///
@@ -137,10 +137,11 @@ pub trait MeterProvider {
137137
/// // Record measurements using the updown counter instrument add()
138138
/// updown_i64_counter.add(
139139
/// -10,
140+
/// &
140141
/// [
141142
/// KeyValue::new("mykey1", "myvalue1"),
142143
/// KeyValue::new("mykey2", "myvalue2"),
143-
/// ].as_ref(),
144+
/// ],
144145
/// );
145146
///
146147
/// // f64 updown counter
@@ -149,10 +150,11 @@ pub trait MeterProvider {
149150
/// // Record measurements using the updown counter instrument add()
150151
/// updown_f64_counter.add(
151152
/// -10.67,
153+
/// &
152154
/// [
153155
/// KeyValue::new("mykey1", "myvalue1"),
154156
/// KeyValue::new("mykey2", "myvalue2"),
155-
/// ].as_ref(),
157+
/// ],
156158
/// );
157159
///
158160
/// // i64 observable updown counter
@@ -163,10 +165,10 @@ pub trait MeterProvider {
163165
/// observer.observe_i64(
164166
/// &observable_i64_up_down_counter,
165167
/// 1,
166-
/// [
168+
/// &[
167169
/// KeyValue::new("mykey1", "myvalue1"),
168170
/// KeyValue::new("mykey2", "myvalue2"),
169-
/// ].as_ref(),
171+
/// ],
170172
/// )
171173
/// });
172174
///
@@ -178,10 +180,10 @@ pub trait MeterProvider {
178180
/// observer.observe_f64(
179181
/// &observable_f64_up_down_counter,
180182
/// 1.16,
181-
/// [
183+
/// &[
182184
/// KeyValue::new("mykey1", "myvalue1"),
183185
/// KeyValue::new("mykey2", "myvalue2"),
184-
/// ].as_ref(),
186+
/// ],
185187
/// )
186188
/// });
187189
///
@@ -193,10 +195,10 @@ pub trait MeterProvider {
193195
/// observer.observe_f64(
194196
/// &f64_gauge,
195197
/// 2.32,
196-
/// [
198+
/// &[
197199
/// KeyValue::new("mykey1", "myvalue1"),
198200
/// KeyValue::new("mykey2", "myvalue2"),
199-
/// ].as_ref(),
201+
/// ],
200202
/// )
201203
/// });
202204
///
@@ -208,10 +210,10 @@ pub trait MeterProvider {
208210
/// observer.observe_i64(
209211
/// &i64_gauge,
210212
/// 12,
211-
/// [
213+
/// &[
212214
/// KeyValue::new("mykey1", "myvalue1"),
213215
/// KeyValue::new("mykey2", "myvalue2"),
214-
/// ].as_ref(),
216+
/// ],
215217
/// )
216218
/// });
217219
///
@@ -223,10 +225,10 @@ pub trait MeterProvider {
223225
/// observer.observe_u64(
224226
/// &u64_gauge,
225227
/// 1,
226-
/// [
228+
/// &[
227229
/// KeyValue::new("mykey1", "myvalue1"),
228230
/// KeyValue::new("mykey2", "myvalue2"),
229-
/// ].as_ref(),
231+
/// ],
230232
/// )
231233
/// });
232234
///
@@ -236,11 +238,10 @@ pub trait MeterProvider {
236238
/// // Record measurements using the histogram instrument record()
237239
/// f64_histogram.record(
238240
/// 10.5,
239-
/// [
241+
/// &[
240242
/// KeyValue::new("mykey1", "myvalue1"),
241243
/// KeyValue::new("mykey2", "myvalue2"),
242-
/// ]
243-
/// .as_ref(),
244+
/// ],
244245
/// );
245246
///
246247
/// // u64 histogram
@@ -249,11 +250,10 @@ pub trait MeterProvider {
249250
/// // Record measurements using the histogram instrument record()
250251
/// u64_histogram.record(
251252
/// 12,
252-
/// [
253+
/// &[
253254
/// KeyValue::new("mykey1", "myvalue1"),
254255
/// KeyValue::new("mykey2", "myvalue2"),
255-
/// ]
256-
/// .as_ref(),
256+
/// ],
257257
/// );
258258
///
259259
/// ```

0 commit comments

Comments
 (0)