@@ -874,6 +874,85 @@ def test_record_exception(self):
874
874
exception_event .attributes ["exception.stacktrace" ],
875
875
)
876
876
877
+ def test_record_exception_with_attributes (self ):
878
+ span = trace ._Span ("name" , mock .Mock (spec = trace_api .SpanContext ))
879
+ try :
880
+ raise RuntimeError ("error" )
881
+ except RuntimeError as err :
882
+ attributes = {"has_additional_attributes" : True }
883
+ span .record_exception (err , attributes )
884
+ exception_event = span .events [0 ]
885
+ self .assertEqual ("exception" , exception_event .name )
886
+ self .assertEqual (
887
+ "error" , exception_event .attributes ["exception.message" ]
888
+ )
889
+ self .assertEqual (
890
+ "RuntimeError" , exception_event .attributes ["exception.type" ]
891
+ )
892
+ self .assertIn (
893
+ "RuntimeError: error" ,
894
+ exception_event .attributes ["exception.stacktrace" ],
895
+ )
896
+ self .assertIn (
897
+ "has_additional_attributes" , exception_event .attributes ,
898
+ )
899
+ self .assertEqual (
900
+ True , exception_event .attributes ["has_additional_attributes" ],
901
+ )
902
+
903
+ def test_record_exception_with_timestamp (self ):
904
+ span = trace ._Span ("name" , mock .Mock (spec = trace_api .SpanContext ))
905
+ try :
906
+ raise RuntimeError ("error" )
907
+ except RuntimeError as err :
908
+ timestamp = 1604238587112021089
909
+ span .record_exception (err , timestamp = timestamp )
910
+ exception_event = span .events [0 ]
911
+ self .assertEqual ("exception" , exception_event .name )
912
+ self .assertEqual (
913
+ "error" , exception_event .attributes ["exception.message" ]
914
+ )
915
+ self .assertEqual (
916
+ "RuntimeError" , exception_event .attributes ["exception.type" ]
917
+ )
918
+ self .assertIn (
919
+ "RuntimeError: error" ,
920
+ exception_event .attributes ["exception.stacktrace" ],
921
+ )
922
+ self .assertEqual (
923
+ 1604238587112021089 , exception_event .timestamp ,
924
+ )
925
+
926
+ def test_record_exception_with_attributes_and_timestamp (self ):
927
+ span = trace ._Span ("name" , mock .Mock (spec = trace_api .SpanContext ))
928
+ try :
929
+ raise RuntimeError ("error" )
930
+ except RuntimeError as err :
931
+ attributes = {"has_additional_attributes" : True }
932
+ timestamp = 1604238587112021089
933
+ span .record_exception (err , attributes , timestamp )
934
+ exception_event = span .events [0 ]
935
+ self .assertEqual ("exception" , exception_event .name )
936
+ self .assertEqual (
937
+ "error" , exception_event .attributes ["exception.message" ]
938
+ )
939
+ self .assertEqual (
940
+ "RuntimeError" , exception_event .attributes ["exception.type" ]
941
+ )
942
+ self .assertIn (
943
+ "RuntimeError: error" ,
944
+ exception_event .attributes ["exception.stacktrace" ],
945
+ )
946
+ self .assertIn (
947
+ "has_additional_attributes" , exception_event .attributes ,
948
+ )
949
+ self .assertEqual (
950
+ True , exception_event .attributes ["has_additional_attributes" ],
951
+ )
952
+ self .assertEqual (
953
+ 1604238587112021089 , exception_event .timestamp ,
954
+ )
955
+
877
956
def test_record_exception_context_manager (self ):
878
957
try :
879
958
with self .tracer .start_as_current_span ("span" ) as span :
0 commit comments