Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def failed(self, event: monitoring.CommandFailedEvent):
if span is None:
return
if span.is_recording():
span.set_status(Status(StatusCode.ERROR, event.failure))
span.set_status(Status(StatusCode.ERROR, event.failure.get("errmsg", "Unknown error")))
try:
self.failed_hook(span, event)
except (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def test_failed(self):
failed_hook=self.failed_callback,
)
command_tracer.started(event=mock_event)
mock_event.mark_as_failed()
command_tracer.failed(event=mock_event)

spans_list = self.memory_exporter.get_finished_spans()
Expand All @@ -137,7 +138,7 @@ def test_failed(self):
span.status.status_code,
trace_api.StatusCode.ERROR,
)
self.assertEqual(span.status.description, "failure")
self.assertEqual(span.status.description, "operation failed")
self.assertIsNotNone(span.end_time)
self.start_callback.assert_called_once()
self.failed_callback.assert_called_once()
Expand All @@ -149,6 +150,7 @@ def test_multiple_commands(self):
command_tracer.started(event=first_mock_event)
command_tracer.started(event=second_mock_event)
command_tracer.succeeded(event=first_mock_event)
second_mock_event.mark_as_failed()
command_tracer.failed(event=second_mock_event)

spans_list = self.memory_exporter.get_finished_spans()
Expand Down Expand Up @@ -292,5 +294,16 @@ def __init__(self, command_attrs, connection_id=None, request_id=""):
self.connection_id = connection_id
self.request_id = request_id

def mark_as_failed(self):
# CommandFailedEvent.failure is type _DocumentOut, which pymongo defines as:
# ```
# _DocumentOut = Union[MutableMapping[str, Any], "RawBSONDocument"]
# ```
# we go with the former, but both provide a `.get(key, default)` method.
#
self.failure = {
"errmsg": "operation failed"
}

def __getattr__(self, item):
return item
Loading