@@ -127,6 +127,7 @@ def test_failed(self):
127127 failed_hook = self .failed_callback ,
128128 )
129129 command_tracer .started (event = mock_event )
130+ mock_event .mark_as_failed ()
130131 command_tracer .failed (event = mock_event )
131132
132133 spans_list = self .memory_exporter .get_finished_spans ()
@@ -137,7 +138,7 @@ def test_failed(self):
137138 span .status .status_code ,
138139 trace_api .StatusCode .ERROR ,
139140 )
140- self .assertEqual (span .status .description , "failure " )
141+ self .assertEqual (span .status .description , "operation failed " )
141142 self .assertIsNotNone (span .end_time )
142143 self .start_callback .assert_called_once ()
143144 self .failed_callback .assert_called_once ()
@@ -149,6 +150,7 @@ def test_multiple_commands(self):
149150 command_tracer .started (event = first_mock_event )
150151 command_tracer .started (event = second_mock_event )
151152 command_tracer .succeeded (event = first_mock_event )
153+ second_mock_event .mark_as_failed ()
152154 command_tracer .failed (event = second_mock_event )
153155
154156 spans_list = self .memory_exporter .get_finished_spans ()
@@ -292,5 +294,16 @@ def __init__(self, command_attrs, connection_id=None, request_id=""):
292294 self .connection_id = connection_id
293295 self .request_id = request_id
294296
297+ def mark_as_failed (self ):
298+ # CommandFailedEvent.failure is type _DocumentOut, which pymongo defines as:
299+ # ```
300+ # _DocumentOut = Union[MutableMapping[str, Any], "RawBSONDocument"]
301+ # ```
302+ # we go with the former, but both provide a `.get(key, default)` method.
303+ #
304+ self .failure = {
305+ "errmsg" : "operation failed"
306+ }
307+
295308 def __getattr__ (self , item ):
296309 return item
0 commit comments