@@ -6,7 +6,7 @@ use opentelemetry_sdk::{
6
6
AggregationSelector , DefaultAggregationSelector , DefaultTemporalitySelector ,
7
7
MetricReader , TemporalitySelector ,
8
8
} ,
9
- AttributeSet , InstrumentKind , ManualReader , MeterProviderBuilder , SdkMeterProvider ,
9
+ InstrumentKind , ManualReader , MeterProviderBuilder , SdkMeterProvider ,
10
10
} ,
11
11
Resource ,
12
12
} ;
@@ -195,16 +195,13 @@ async fn u64_counter_with_attributes_is_exported() {
195
195
"hello_world" . to_string ( ) ,
196
196
InstrumentKind :: Counter ,
197
197
1_u64 ,
198
- Some ( AttributeSet :: from (
199
- [
200
- KeyValue :: new ( "u64_key_1" , 1_i64 ) ,
201
- KeyValue :: new ( "i64_key_1" , 2_i64 ) ,
202
- KeyValue :: new ( "f64_key_1" , 3_f64 ) ,
203
- KeyValue :: new ( "str_key_1" , "foo" ) ,
204
- KeyValue :: new ( "bool_key_1" , true ) ,
205
- ]
206
- . as_slice ( ) ,
207
- ) ) ,
198
+ Some ( vec ! [
199
+ KeyValue :: new( "u64_key_1" , 1_i64 ) ,
200
+ KeyValue :: new( "i64_key_1" , 2_i64 ) ,
201
+ KeyValue :: new( "f64_key_1" , 3_f64 ) ,
202
+ KeyValue :: new( "str_key_1" , "foo" ) ,
203
+ KeyValue :: new( "bool_key_1" , true ) ,
204
+ ] ) ,
208
205
) ;
209
206
210
207
tracing:: subscriber:: with_default ( subscriber, || {
@@ -227,16 +224,13 @@ async fn f64_counter_with_attributes_is_exported() {
227
224
"hello_world" . to_string ( ) ,
228
225
InstrumentKind :: Counter ,
229
226
1_f64 ,
230
- Some ( AttributeSet :: from (
231
- [
232
- KeyValue :: new ( "u64_key_1" , 1_i64 ) ,
233
- KeyValue :: new ( "i64_key_1" , 2_i64 ) ,
234
- KeyValue :: new ( "f64_key_1" , 3_f64 ) ,
235
- KeyValue :: new ( "str_key_1" , "foo" ) ,
236
- KeyValue :: new ( "bool_key_1" , true ) ,
237
- ]
238
- . as_slice ( ) ,
239
- ) ) ,
227
+ Some ( vec ! [
228
+ KeyValue :: new( "u64_key_1" , 1_i64 ) ,
229
+ KeyValue :: new( "i64_key_1" , 2_i64 ) ,
230
+ KeyValue :: new( "f64_key_1" , 3_f64 ) ,
231
+ KeyValue :: new( "str_key_1" , "foo" ) ,
232
+ KeyValue :: new( "bool_key_1" , true ) ,
233
+ ] ) ,
240
234
) ;
241
235
242
236
tracing:: subscriber:: with_default ( subscriber, || {
@@ -259,16 +253,13 @@ async fn i64_up_down_counter_with_attributes_is_exported() {
259
253
"hello_world" . to_string ( ) ,
260
254
InstrumentKind :: UpDownCounter ,
261
255
-1_i64 ,
262
- Some ( AttributeSet :: from (
263
- [
264
- KeyValue :: new ( "u64_key_1" , 1_i64 ) ,
265
- KeyValue :: new ( "i64_key_1" , 2_i64 ) ,
266
- KeyValue :: new ( "f64_key_1" , 3_f64 ) ,
267
- KeyValue :: new ( "str_key_1" , "foo" ) ,
268
- KeyValue :: new ( "bool_key_1" , true ) ,
269
- ]
270
- . as_slice ( ) ,
271
- ) ) ,
256
+ Some ( vec ! [
257
+ KeyValue :: new( "u64_key_1" , 1_i64 ) ,
258
+ KeyValue :: new( "i64_key_1" , 2_i64 ) ,
259
+ KeyValue :: new( "f64_key_1" , 3_f64 ) ,
260
+ KeyValue :: new( "str_key_1" , "foo" ) ,
261
+ KeyValue :: new( "bool_key_1" , true ) ,
262
+ ] ) ,
272
263
) ;
273
264
274
265
tracing:: subscriber:: with_default ( subscriber, || {
@@ -291,16 +282,13 @@ async fn f64_up_down_counter_with_attributes_is_exported() {
291
282
"hello_world" . to_string ( ) ,
292
283
InstrumentKind :: UpDownCounter ,
293
284
-1_f64 ,
294
- Some ( AttributeSet :: from (
295
- [
296
- KeyValue :: new ( "u64_key_1" , 1_i64 ) ,
297
- KeyValue :: new ( "i64_key_1" , 2_i64 ) ,
298
- KeyValue :: new ( "f64_key_1" , 3_f64 ) ,
299
- KeyValue :: new ( "str_key_1" , "foo" ) ,
300
- KeyValue :: new ( "bool_key_1" , true ) ,
301
- ]
302
- . as_slice ( ) ,
303
- ) ) ,
285
+ Some ( vec ! [
286
+ KeyValue :: new( "u64_key_1" , 1_i64 ) ,
287
+ KeyValue :: new( "i64_key_1" , 2_i64 ) ,
288
+ KeyValue :: new( "f64_key_1" , 3_f64 ) ,
289
+ KeyValue :: new( "str_key_1" , "foo" ) ,
290
+ KeyValue :: new( "bool_key_1" , true ) ,
291
+ ] ) ,
304
292
) ;
305
293
306
294
tracing:: subscriber:: with_default ( subscriber, || {
@@ -324,16 +312,13 @@ async fn f64_gauge_with_attributes_is_exported() {
324
312
"hello_world" . to_string ( ) ,
325
313
InstrumentKind :: Gauge ,
326
314
1_f64 ,
327
- Some ( AttributeSet :: from (
328
- [
329
- KeyValue :: new ( "u64_key_1" , 1_i64 ) ,
330
- KeyValue :: new ( "i64_key_1" , 2_i64 ) ,
331
- KeyValue :: new ( "f64_key_1" , 3_f64 ) ,
332
- KeyValue :: new ( "str_key_1" , "foo" ) ,
333
- KeyValue :: new ( "bool_key_1" , true ) ,
334
- ]
335
- . as_slice ( ) ,
336
- ) ) ,
315
+ Some ( vec ! [
316
+ KeyValue :: new( "u64_key_1" , 1_i64 ) ,
317
+ KeyValue :: new( "i64_key_1" , 2_i64 ) ,
318
+ KeyValue :: new( "f64_key_1" , 3_f64 ) ,
319
+ KeyValue :: new( "str_key_1" , "foo" ) ,
320
+ KeyValue :: new( "bool_key_1" , true ) ,
321
+ ] ) ,
337
322
) ;
338
323
339
324
tracing:: subscriber:: with_default ( subscriber, || {
@@ -357,16 +342,13 @@ async fn u64_gauge_with_attributes_is_exported() {
357
342
"hello_world" . to_string ( ) ,
358
343
InstrumentKind :: Gauge ,
359
344
1_u64 ,
360
- Some ( AttributeSet :: from (
361
- [
362
- KeyValue :: new ( "u64_key_1" , 1_i64 ) ,
363
- KeyValue :: new ( "i64_key_1" , 2_i64 ) ,
364
- KeyValue :: new ( "f64_key_1" , 3_f64 ) ,
365
- KeyValue :: new ( "str_key_1" , "foo" ) ,
366
- KeyValue :: new ( "bool_key_1" , true ) ,
367
- ]
368
- . as_slice ( ) ,
369
- ) ) ,
345
+ Some ( vec ! [
346
+ KeyValue :: new( "u64_key_1" , 1_i64 ) ,
347
+ KeyValue :: new( "i64_key_1" , 2_i64 ) ,
348
+ KeyValue :: new( "f64_key_1" , 3_f64 ) ,
349
+ KeyValue :: new( "str_key_1" , "foo" ) ,
350
+ KeyValue :: new( "bool_key_1" , true ) ,
351
+ ] ) ,
370
352
) ;
371
353
372
354
tracing:: subscriber:: with_default ( subscriber, || {
@@ -390,16 +372,13 @@ async fn i64_gauge_with_attributes_is_exported() {
390
372
"hello_world" . to_string ( ) ,
391
373
InstrumentKind :: Gauge ,
392
374
1_i64 ,
393
- Some ( AttributeSet :: from (
394
- [
395
- KeyValue :: new ( "u64_key_1" , 1_i64 ) ,
396
- KeyValue :: new ( "i64_key_1" , 2_i64 ) ,
397
- KeyValue :: new ( "f64_key_1" , 3_f64 ) ,
398
- KeyValue :: new ( "str_key_1" , "foo" ) ,
399
- KeyValue :: new ( "bool_key_1" , true ) ,
400
- ]
401
- . as_slice ( ) ,
402
- ) ) ,
375
+ Some ( vec ! [
376
+ KeyValue :: new( "u64_key_1" , 1_i64 ) ,
377
+ KeyValue :: new( "i64_key_1" , 2_i64 ) ,
378
+ KeyValue :: new( "f64_key_1" , 3_f64 ) ,
379
+ KeyValue :: new( "str_key_1" , "foo" ) ,
380
+ KeyValue :: new( "bool_key_1" , true ) ,
381
+ ] ) ,
403
382
) ;
404
383
405
384
tracing:: subscriber:: with_default ( subscriber, || {
@@ -422,16 +401,13 @@ async fn u64_histogram_with_attributes_is_exported() {
422
401
"hello_world" . to_string ( ) ,
423
402
InstrumentKind :: Histogram ,
424
403
1_u64 ,
425
- Some ( AttributeSet :: from (
426
- [
427
- KeyValue :: new ( "u64_key_1" , 1_i64 ) ,
428
- KeyValue :: new ( "i64_key_1" , 2_i64 ) ,
429
- KeyValue :: new ( "f64_key_1" , 3_f64 ) ,
430
- KeyValue :: new ( "str_key_1" , "foo" ) ,
431
- KeyValue :: new ( "bool_key_1" , true ) ,
432
- ]
433
- . as_slice ( ) ,
434
- ) ) ,
404
+ Some ( vec ! [
405
+ KeyValue :: new( "u64_key_1" , 1_i64 ) ,
406
+ KeyValue :: new( "i64_key_1" , 2_i64 ) ,
407
+ KeyValue :: new( "f64_key_1" , 3_f64 ) ,
408
+ KeyValue :: new( "str_key_1" , "foo" ) ,
409
+ KeyValue :: new( "bool_key_1" , true ) ,
410
+ ] ) ,
435
411
) ;
436
412
437
413
tracing:: subscriber:: with_default ( subscriber, || {
@@ -454,16 +430,13 @@ async fn f64_histogram_with_attributes_is_exported() {
454
430
"hello_world" . to_string ( ) ,
455
431
InstrumentKind :: Histogram ,
456
432
1_f64 ,
457
- Some ( AttributeSet :: from (
458
- [
459
- KeyValue :: new ( "u64_key_1" , 1_i64 ) ,
460
- KeyValue :: new ( "i64_key_1" , 2_i64 ) ,
461
- KeyValue :: new ( "f64_key_1" , 3_f64 ) ,
462
- KeyValue :: new ( "str_key_1" , "foo" ) ,
463
- KeyValue :: new ( "bool_key_1" , true ) ,
464
- ]
465
- . as_slice ( ) ,
466
- ) ) ,
433
+ Some ( vec ! [
434
+ KeyValue :: new( "u64_key_1" , 1_i64 ) ,
435
+ KeyValue :: new( "i64_key_1" , 2_i64 ) ,
436
+ KeyValue :: new( "f64_key_1" , 3_f64 ) ,
437
+ KeyValue :: new( "str_key_1" , "foo" ) ,
438
+ KeyValue :: new( "bool_key_1" , true ) ,
439
+ ] ) ,
467
440
) ;
468
441
469
442
tracing:: subscriber:: with_default ( subscriber, || {
@@ -486,9 +459,7 @@ async fn display_attribute_is_exported() {
486
459
"hello_world" . to_string ( ) ,
487
460
InstrumentKind :: Counter ,
488
461
1_u64 ,
489
- Some ( AttributeSet :: from (
490
- [ KeyValue :: new ( "display_key_1" , "display: foo" ) ] . as_slice ( ) ,
491
- ) ) ,
462
+ Some ( vec ! [ KeyValue :: new( "display_key_1" , "display: foo" ) ] ) ,
492
463
) ;
493
464
494
465
struct DisplayAttribute ( String ) ;
@@ -517,9 +488,7 @@ async fn debug_attribute_is_exported() {
517
488
"hello_world" . to_string ( ) ,
518
489
InstrumentKind :: Counter ,
519
490
1_u64 ,
520
- Some ( AttributeSet :: from (
521
- [ KeyValue :: new ( "debug_key_1" , "debug: foo" ) ] . as_slice ( ) ,
522
- ) ) ,
491
+ Some ( vec ! [ KeyValue :: new( "debug_key_1" , "debug: foo" ) ] ) ,
523
492
) ;
524
493
525
494
struct DebugAttribute ( String ) ;
@@ -546,7 +515,7 @@ fn init_subscriber<T>(
546
515
expected_metric_name : String ,
547
516
expected_instrument_kind : InstrumentKind ,
548
517
expected_value : T ,
549
- expected_attributes : Option < AttributeSet > ,
518
+ expected_attributes : Option < Vec < KeyValue > > ,
550
519
) -> ( impl Subscriber + ' static , TestExporter < T > ) {
551
520
let reader = ManualReader :: builder ( )
552
521
. with_aggregation_selector ( DefaultAggregationSelector :: new ( ) )
@@ -563,12 +532,7 @@ fn init_subscriber<T>(
563
532
expected_metric_name,
564
533
expected_instrument_kind,
565
534
expected_value,
566
- expected_attributes : expected_attributes. map ( |attrs| {
567
- attrs
568
- . iter ( )
569
- . map ( |( k, v) | KeyValue :: new ( k. clone ( ) , v. clone ( ) ) )
570
- . collect ( )
571
- } ) ,
535
+ expected_attributes,
572
536
reader,
573
537
_meter_provider : provider. clone ( ) ,
574
538
} ;
@@ -659,7 +623,10 @@ where
659
623
660
624
if let Some ( expected_attributes) = self . expected_attributes . as_ref ( ) {
661
625
sum. data_points . iter ( ) . for_each ( |data_point| {
662
- assert_eq ! ( expected_attributes, & data_point. attributes)
626
+ assert ! ( compare_attributes(
627
+ expected_attributes,
628
+ & data_point. attributes,
629
+ ) )
663
630
} ) ;
664
631
}
665
632
}
@@ -677,7 +644,10 @@ where
677
644
678
645
if let Some ( expected_attributes) = self . expected_attributes . as_ref ( ) {
679
646
gauge. data_points . iter ( ) . for_each ( |data_point| {
680
- assert_eq ! ( expected_attributes, & data_point. attributes)
647
+ assert ! ( compare_attributes(
648
+ expected_attributes,
649
+ & data_point. attributes,
650
+ ) )
681
651
} ) ;
682
652
}
683
653
}
@@ -689,7 +659,10 @@ where
689
659
assert_eq ! ( histogram_data. sum, self . expected_value) ;
690
660
691
661
if let Some ( expected_attributes) = self . expected_attributes . as_ref ( ) {
692
- assert_eq ! ( expected_attributes, & histogram_data. attributes) ;
662
+ assert ! ( compare_attributes(
663
+ expected_attributes,
664
+ & histogram_data. attributes
665
+ ) )
693
666
}
694
667
}
695
668
unexpected => {
@@ -702,3 +675,16 @@ where
702
675
Ok ( ( ) )
703
676
}
704
677
}
678
+
679
+ // After sorting the KeyValue vec, compare them.
680
+ // Return true if they are equal.
681
+ #[ allow( clippy:: ptr_arg) ]
682
+ fn compare_attributes ( expected : & Vec < KeyValue > , actual : & Vec < KeyValue > ) -> bool {
683
+ let mut expected = expected. clone ( ) ;
684
+ let mut actual = actual. clone ( ) ;
685
+
686
+ expected. sort ( ) ;
687
+ actual. sort ( ) ;
688
+
689
+ expected == actual
690
+ }
0 commit comments