3333from opentelemetry .proto .resource .v1 .resource_pb2 import (
3434 Resource as OTLPResource ,
3535)
36+ from opentelemetry .sdk .metrics import Exemplar
3637from opentelemetry .sdk .metrics .export import (
3738 AggregationTemporality ,
3839 Buckets ,
5556
5657
5758class TestOTLPMetricsEncoder (unittest .TestCase ):
59+ span_id = int ("6e0c63257de34c92" , 16 )
60+ trace_id = int ("d4cda95b652f4a1592b449d5929fda1b" , 16 )
61+
5862 histogram = Metric (
5963 name = "histogram" ,
6064 description = "foo" ,
@@ -65,6 +69,22 @@ class TestOTLPMetricsEncoder(unittest.TestCase):
6569 attributes = {"a" : 1 , "b" : True },
6670 start_time_unix_nano = 1641946016139533244 ,
6771 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+ ],
6888 count = 5 ,
6989 sum = 67 ,
7090 bucket_counts = [1 , 4 ],
@@ -460,7 +480,34 @@ def test_encode_histogram(self):
460480 sum = 67 ,
461481 bucket_counts = [1 , 4 ],
462482 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+ ],
464511 max = 18.0 ,
465512 min = 8.0 ,
466513 )
@@ -563,7 +610,34 @@ def test_encode_multiple_scope_histogram(self):
563610 sum = 67 ,
564611 bucket_counts = [1 , 4 ],
565612 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+ ],
567641 max = 18.0 ,
568642 min = 8.0 ,
569643 )
@@ -598,7 +672,34 @@ def test_encode_multiple_scope_histogram(self):
598672 sum = 67 ,
599673 bucket_counts = [1 , 4 ],
600674 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+ ],
602703 max = 18.0 ,
603704 min = 8.0 ,
604705 )
@@ -640,7 +741,34 @@ def test_encode_multiple_scope_histogram(self):
640741 sum = 67 ,
641742 bucket_counts = [1 , 4 ],
642743 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+ ],
644772 max = 18.0 ,
645773 min = 8.0 ,
646774 )
@@ -682,7 +810,34 @@ def test_encode_multiple_scope_histogram(self):
682810 sum = 67 ,
683811 bucket_counts = [1 , 4 ],
684812 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+ ],
686841 max = 18.0 ,
687842 min = 8.0 ,
688843 )
0 commit comments