@@ -838,7 +838,7 @@ def test_otel_span_extended_reserved_attributes_overrides_analytics_event(
838
838
@missing_feature (context .library == "php" , reason = "Not implemented" )
839
839
@missing_feature (context .library == "java" , reason = "Not implemented" )
840
840
@missing_feature (context .library == "ruby" , reason = "Not implemented" )
841
- @missing_feature (context .library == "nodejs" , reason = "Not implemented " )
841
+ @missing_feature (context .library < "nodejs@5.17.0 " , reason = "Implemented in v5.17.0 & v4.41.0 " )
842
842
@missing_feature (context .library == "dotnet" , reason = "Not implemented" )
843
843
@missing_feature (context .library < "[email protected] " , reason = "Not implemented" )
844
844
def test_otel_add_event_meta_serialization (self , test_agent , test_library ):
@@ -874,7 +874,7 @@ def test_otel_add_event_meta_serialization(self, test_agent, test_library):
874
874
875
875
event2 = events [1 ]
876
876
assert event2 .get ("name" ) == "second_event"
877
- assert event2 .get ("time_unix_nano" ) == event2_timestamp_ns
877
+ assert event2 .get ("time_unix_nano" ) // 10000 == event2_timestamp_ns // 10000 # reduce the precision tested
878
878
assert event2 ["attributes" ].get ("string_val" ) == "value"
879
879
880
880
event3 = events [2 ]
@@ -891,7 +891,7 @@ def test_otel_add_event_meta_serialization(self, test_agent, test_library):
891
891
@missing_feature (context .library == "php" , reason = "Not implemented" )
892
892
@missing_feature (context .library == "java" , reason = "Not implemented" )
893
893
@missing_feature (context .library == "ruby" , reason = "Not implemented" )
894
- @missing_feature (context .library == "nodejs" , reason = "Not implemented " )
894
+ @missing_feature (context .library < "nodejs@5.17.0 " , reason = "Implemented in v5.17.0 & v4.41.0 " )
895
895
@missing_feature (context .library < "[email protected] " , reason = "Not implemented" )
896
896
def test_otel_record_exception_does_not_set_error (self , test_agent , test_library ):
897
897
"""
@@ -910,7 +910,7 @@ def test_otel_record_exception_does_not_set_error(self, test_agent, test_library
910
910
@missing_feature (context .library == "php" , reason = "Not implemented" )
911
911
@missing_feature (context .library == "java" , reason = "Not implemented" )
912
912
@missing_feature (context .library == "ruby" , reason = "Not implemented" )
913
- @missing_feature (context .library == "nodejs" , reason = "Not implemented " )
913
+ @missing_feature (context .library < "nodejs@5.17.0 " , reason = "Implemented in v5.17.0 & v4.41.0 " )
914
914
@missing_feature (context .library == "dotnet" , reason = "Not implemented" )
915
915
@missing_feature (context .library < "[email protected] " , reason = "Not implemented" )
916
916
def test_otel_record_exception_meta_serialization (self , test_agent , test_library ):
@@ -933,29 +933,64 @@ def test_otel_record_exception_meta_serialization(self, test_agent, test_library
933
933
934
934
events = json .loads (root_span .get ("meta" , {}).get ("events" ))
935
935
assert len (events ) == 3
936
+ event1 = events [0 ]
937
+ assert (
938
+ event1 .get ("name" ).lower () == "exception" or "error"
939
+ ) # node uses error objects instead of exception objects
940
+ assert event1 .get ("time_unix_nano" ) > 0
941
+
942
+ event2 = events [1 ]
943
+ assert event2 .get ("name" ) == "non_exception_event"
944
+ assert event2 .get ("time_unix_nano" ) > event1 .get ("time_unix_nano" )
945
+
946
+ event3 = events [2 ]
947
+ assert event3 .get ("name" ) == "exception" or "error"
948
+ assert event3 .get ("time_unix_nano" ) > event2 .get ("time_unix_nano" )
949
+
950
+ assert root_span ["error" ] == 1
951
+ assert "error.type" in root_span ["meta" ]
952
+ assert "error.stack" in root_span ["meta" ]
953
+
954
+ @missing_feature (context .library == "golang" , reason = "Not implemented" )
955
+ @missing_feature (context .library == "php" , reason = "Not implemented" )
956
+ @missing_feature (context .library == "java" , reason = "Not implemented" )
957
+ @missing_feature (context .library == "ruby" , reason = "Not implemented" )
958
+ @missing_feature (context .library == "nodejs" , reason = "Otel Node.js API does not support attributes" )
959
+ @missing_feature (context .library == "dotnet" , reason = "Not implemented" )
960
+ @missing_feature (context .library < "[email protected] " , reason = "Not implemented" )
961
+ def test_otel_record_exception_attributes_serialization (self , test_agent , test_library ):
962
+ """
963
+ Tests the Span.RecordException API (requires Span.AddEvent API support)
964
+ and its serialization into the Datadog error tags and the 'events' tag
965
+ """
966
+ with test_library :
967
+ with test_library .otel_start_span ("operation" ) as span :
968
+ span .set_status (OTEL_ERROR_CODE , "error_desc" )
969
+ span .record_exception (
970
+ message = "woof1" , attributes = {"string_val" : "value" , "exception.stacktrace" : "stacktrace1" }
971
+ )
972
+ span .add_event (name = "non_exception_event" , attributes = {"exception.stacktrace" : "non-error" })
973
+ span .record_exception (message = "woof3" , attributes = {"exception.message" : "message override" })
974
+ span .end_span ()
936
975
976
+ root_span = get_span (test_agent )
977
+ assert "events" in root_span ["meta" ]
978
+
979
+ events = json .loads (root_span .get ("meta" , {}).get ("events" ))
980
+ assert len (events ) == 3
937
981
event1 = events [0 ]
938
- assert event1 .get ("name" ) == "exception"
939
982
assert event1 ["attributes" ].get ("string_val" ) == "value"
940
983
assert event1 ["attributes" ].get ("exception.message" ) == "woof1"
941
984
assert event1 ["attributes" ].get ("exception.stacktrace" ) == "stacktrace1"
942
- assert event1 .get ("time_unix_nano" ) > 0
943
985
944
986
event2 = events [1 ]
945
- assert event2 .get ("name" ) == "non_exception_event"
946
987
assert event2 ["attributes" ].get ("exception.stacktrace" ) == "non-error"
947
- assert event2 .get ("time_unix_nano" ) > event1 .get ("time_unix_nano" )
948
988
949
989
event3 = events [2 ]
950
- assert event3 .get ("name" ) == "exception"
951
990
assert event3 ["attributes" ].get ("exception.message" ) == "message override"
952
- assert event3 .get ("time_unix_nano" ) > event2 .get ("time_unix_nano" )
953
991
954
- assert root_span ["error" ] == 1
955
992
error_message = root_span ["meta" ].get ("error.message" ) or root_span ["meta" ].get ("error.msg" )
956
993
assert error_message == "message override"
957
- assert "error.type" in root_span ["meta" ]
958
- assert "error.stack" in root_span ["meta" ]
959
994
960
995
961
996
def run_operation_name_test (expected_operation_name : str , span_kind : int , attributes : dict , test_library , test_agent ):
0 commit comments