33
33
from opentelemetry .proto .resource .v1 .resource_pb2 import (
34
34
Resource as OTLPResource ,
35
35
)
36
+ from opentelemetry .sdk .metrics import Exemplar
36
37
from opentelemetry .sdk .metrics .export import (
37
38
AggregationTemporality ,
38
39
Buckets ,
55
56
56
57
57
58
class TestOTLPMetricsEncoder (unittest .TestCase ):
59
+ span_id = int ("6e0c63257de34c92" , 16 )
60
+ trace_id = int ("d4cda95b652f4a1592b449d5929fda1b" , 16 )
61
+
58
62
histogram = Metric (
59
63
name = "histogram" ,
60
64
description = "foo" ,
@@ -65,6 +69,22 @@ class TestOTLPMetricsEncoder(unittest.TestCase):
65
69
attributes = {"a" : 1 , "b" : True },
66
70
start_time_unix_nano = 1641946016139533244 ,
67
71
time_unix_nano = 1641946016139533244 ,
72
+ exemplars = [
73
+ Exemplar (
74
+ {"filtered" : "banana" },
75
+ 298.0 ,
76
+ 1641946016139533400 ,
77
+ span_id ,
78
+ trace_id ,
79
+ ),
80
+ Exemplar (
81
+ {"filtered" : "banana" },
82
+ 298.0 ,
83
+ 1641946016139533400 ,
84
+ None ,
85
+ None ,
86
+ ),
87
+ ],
68
88
count = 5 ,
69
89
sum = 67 ,
70
90
bucket_counts = [1 , 4 ],
@@ -460,7 +480,34 @@ def test_encode_histogram(self):
460
480
sum = 67 ,
461
481
bucket_counts = [1 , 4 ],
462
482
explicit_bounds = [10.0 , 20.0 ],
463
- exemplars = [],
483
+ exemplars = [
484
+ pb2 .Exemplar (
485
+ time_unix_nano = 1641946016139533400 ,
486
+ as_double = 298 ,
487
+ span_id = b"n\x0c c%}\xe3 L\x92 " ,
488
+ trace_id = b"\xd4 \xcd \xa9 [e/J\x15 \x92 \xb4 I\xd5 \x92 \x9f \xda \x1b " ,
489
+ filtered_attributes = [
490
+ KeyValue (
491
+ key = "filtered" ,
492
+ value = AnyValue (
493
+ string_value = "banana"
494
+ ),
495
+ )
496
+ ],
497
+ ),
498
+ pb2 .Exemplar (
499
+ time_unix_nano = 1641946016139533400 ,
500
+ as_double = 298 ,
501
+ filtered_attributes = [
502
+ KeyValue (
503
+ key = "filtered" ,
504
+ value = AnyValue (
505
+ string_value = "banana"
506
+ ),
507
+ )
508
+ ],
509
+ ),
510
+ ],
464
511
max = 18.0 ,
465
512
min = 8.0 ,
466
513
)
@@ -563,7 +610,34 @@ def test_encode_multiple_scope_histogram(self):
563
610
sum = 67 ,
564
611
bucket_counts = [1 , 4 ],
565
612
explicit_bounds = [10.0 , 20.0 ],
566
- exemplars = [],
613
+ exemplars = [
614
+ pb2 .Exemplar (
615
+ time_unix_nano = 1641946016139533400 ,
616
+ as_double = 298 ,
617
+ span_id = b"n\x0c c%}\xe3 L\x92 " ,
618
+ trace_id = b"\xd4 \xcd \xa9 [e/J\x15 \x92 \xb4 I\xd5 \x92 \x9f \xda \x1b " ,
619
+ filtered_attributes = [
620
+ KeyValue (
621
+ key = "filtered" ,
622
+ value = AnyValue (
623
+ string_value = "banana"
624
+ ),
625
+ )
626
+ ],
627
+ ),
628
+ pb2 .Exemplar (
629
+ time_unix_nano = 1641946016139533400 ,
630
+ as_double = 298 ,
631
+ filtered_attributes = [
632
+ KeyValue (
633
+ key = "filtered" ,
634
+ value = AnyValue (
635
+ string_value = "banana"
636
+ ),
637
+ )
638
+ ],
639
+ ),
640
+ ],
567
641
max = 18.0 ,
568
642
min = 8.0 ,
569
643
)
@@ -598,7 +672,34 @@ def test_encode_multiple_scope_histogram(self):
598
672
sum = 67 ,
599
673
bucket_counts = [1 , 4 ],
600
674
explicit_bounds = [10.0 , 20.0 ],
601
- exemplars = [],
675
+ exemplars = [
676
+ pb2 .Exemplar (
677
+ time_unix_nano = 1641946016139533400 ,
678
+ as_double = 298 ,
679
+ span_id = b"n\x0c c%}\xe3 L\x92 " ,
680
+ trace_id = b"\xd4 \xcd \xa9 [e/J\x15 \x92 \xb4 I\xd5 \x92 \x9f \xda \x1b " ,
681
+ filtered_attributes = [
682
+ KeyValue (
683
+ key = "filtered" ,
684
+ value = AnyValue (
685
+ string_value = "banana"
686
+ ),
687
+ )
688
+ ],
689
+ ),
690
+ pb2 .Exemplar (
691
+ time_unix_nano = 1641946016139533400 ,
692
+ as_double = 298 ,
693
+ filtered_attributes = [
694
+ KeyValue (
695
+ key = "filtered" ,
696
+ value = AnyValue (
697
+ string_value = "banana"
698
+ ),
699
+ )
700
+ ],
701
+ ),
702
+ ],
602
703
max = 18.0 ,
603
704
min = 8.0 ,
604
705
)
@@ -640,7 +741,34 @@ def test_encode_multiple_scope_histogram(self):
640
741
sum = 67 ,
641
742
bucket_counts = [1 , 4 ],
642
743
explicit_bounds = [10.0 , 20.0 ],
643
- exemplars = [],
744
+ exemplars = [
745
+ pb2 .Exemplar (
746
+ time_unix_nano = 1641946016139533400 ,
747
+ as_double = 298 ,
748
+ span_id = b"n\x0c c%}\xe3 L\x92 " ,
749
+ trace_id = b"\xd4 \xcd \xa9 [e/J\x15 \x92 \xb4 I\xd5 \x92 \x9f \xda \x1b " ,
750
+ filtered_attributes = [
751
+ KeyValue (
752
+ key = "filtered" ,
753
+ value = AnyValue (
754
+ string_value = "banana"
755
+ ),
756
+ )
757
+ ],
758
+ ),
759
+ pb2 .Exemplar (
760
+ time_unix_nano = 1641946016139533400 ,
761
+ as_double = 298 ,
762
+ filtered_attributes = [
763
+ KeyValue (
764
+ key = "filtered" ,
765
+ value = AnyValue (
766
+ string_value = "banana"
767
+ ),
768
+ )
769
+ ],
770
+ ),
771
+ ],
644
772
max = 18.0 ,
645
773
min = 8.0 ,
646
774
)
@@ -682,7 +810,34 @@ def test_encode_multiple_scope_histogram(self):
682
810
sum = 67 ,
683
811
bucket_counts = [1 , 4 ],
684
812
explicit_bounds = [10.0 , 20.0 ],
685
- exemplars = [],
813
+ exemplars = [
814
+ pb2 .Exemplar (
815
+ time_unix_nano = 1641946016139533400 ,
816
+ as_double = 298 ,
817
+ span_id = b"n\x0c c%}\xe3 L\x92 " ,
818
+ trace_id = b"\xd4 \xcd \xa9 [e/J\x15 \x92 \xb4 I\xd5 \x92 \x9f \xda \x1b " ,
819
+ filtered_attributes = [
820
+ KeyValue (
821
+ key = "filtered" ,
822
+ value = AnyValue (
823
+ string_value = "banana"
824
+ ),
825
+ )
826
+ ],
827
+ ),
828
+ pb2 .Exemplar (
829
+ time_unix_nano = 1641946016139533400 ,
830
+ as_double = 298 ,
831
+ filtered_attributes = [
832
+ KeyValue (
833
+ key = "filtered" ,
834
+ value = AnyValue (
835
+ string_value = "banana"
836
+ ),
837
+ )
838
+ ],
839
+ ),
840
+ ],
686
841
max = 18.0 ,
687
842
min = 8.0 ,
688
843
)
0 commit comments