@@ -470,6 +470,7 @@ def test_start_root_span(self, mock_time, mock_log_ctx):
470
470
max_span_batch_size = 50 ,
471
471
firehose_handler = firehose ,
472
472
encoding = Encoding .V2_JSON ,
473
+ annotations = {},
473
474
)
474
475
assert mock_log_ctx .return_value .start .call_count == 1
475
476
assert tracer .is_transport_configured () is True
@@ -729,6 +730,69 @@ def test_update_binary_annotations_non_root_not_traced(self):
729
730
'status' : '200' ,
730
731
}
731
732
733
+ def test_add_annotation_root (self ):
734
+ with zipkin .zipkin_span (
735
+ service_name = 'test_service' ,
736
+ span_name = 'test_span' ,
737
+ transport_handler = MockTransportHandler (),
738
+ sample_rate = 100.0 ,
739
+ annotations = {'abc' : 123 },
740
+ add_logging_annotation = True ,
741
+ ) as span :
742
+ span .add_annotation ('def' , 345 )
743
+ span .add_annotation ('ghi' , timestamp = 678 )
744
+ with mock .patch ('py_zipkin.zipkin.time.time' ) as mock_time :
745
+ mock_time .return_value = 91011
746
+ span .add_annotation ('jkl' )
747
+
748
+ assert span .logging_context .annotations == {
749
+ 'abc' : 123 ,
750
+ 'def' : 345 ,
751
+ 'ghi' : 678 ,
752
+ 'jkl' : 91011 ,
753
+ }
754
+
755
+ def test_add_annotation_non_root (self ):
756
+ context = zipkin .zipkin_span (
757
+ service_name = 'test_service' ,
758
+ span_name = 'test_span' ,
759
+ annotations = {'abc' : 123 },
760
+ )
761
+ context .get_tracer ()._context_stack .push (zipkin .create_attrs_for_span ())
762
+ with context as span :
763
+ span .add_annotation ('def' , 345 )
764
+ span .add_annotation ('ghi' , timestamp = 678 )
765
+ with mock .patch ('py_zipkin.zipkin.time.time' ) as mock_time :
766
+ mock_time .return_value = 91011
767
+ span .add_annotation ('jkl' )
768
+
769
+ assert span .annotations == {
770
+ 'abc' : 123 ,
771
+ 'def' : 345 ,
772
+ 'ghi' : 678 ,
773
+ 'jkl' : 91011 ,
774
+ }
775
+
776
+ def test_add_annotation_non_root_not_traced (self ):
777
+ # nothing happens if the request is not traced
778
+ with zipkin .zipkin_span (
779
+ service_name = 'test_service' ,
780
+ span_name = 'test_span' ,
781
+ annotations = {'abc' : 123 },
782
+ ) as span :
783
+ span .add_annotation ('def' , 345 )
784
+ span .add_annotation ('ghi' , timestamp = 678 )
785
+ with mock .patch ('py_zipkin.zipkin.time.time' ) as mock_time :
786
+ mock_time .return_value = 91011
787
+ span .add_annotation ('jkl' )
788
+
789
+ assert span .annotations == {
790
+ 'abc' : 123 ,
791
+ 'def' : 345 ,
792
+ 'ghi' : 678 ,
793
+ 'jkl' : 91011 ,
794
+ }
795
+
732
796
def test_add_sa_binary_annotation_non_client (self ):
733
797
# Nothing happens if this is not a client span
734
798
context = zipkin .zipkin_span ('test_service' , 'test_span' )
0 commit comments