Visitar URL original
PYTHON-6045 Test error.type equality on the operation span for a serv… · mongodb/mongo-python-driver@437503a · GitHub
Skip to content

Commit 437503a

Browse files
committed
PYTHON-6045 Test error.type equality on the operation span for a server error
Confirms end_operation_span_failure derives error.type from the exception class name even when the underlying failure carries a server error code, rather than the command span's status code.
1 parent e4c3115 commit 437503a

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

‎test/asynchronous/test_otel.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,20 @@ async def test_failure_records_exception_and_status_code(self):
559559
self.assertEqual(span.attributes["error.type"], span.attributes["db.response.status_code"])
560560
self.assertTrue(any(event.name == "exception" for event in span.events))
561561

562+
async def test_operation_span_error_type_is_exception_class_name_for_server_error(self):
563+
client = await self.async_rs_or_single_client(tracing={"enabled": True})
564+
self.exporter.clear()
565+
with self.assertRaises(OperationFailure) as ctx:
566+
await client[self.db.name].command("thisCommandDoesNotExist")
567+
568+
(op_span,) = [
569+
s
570+
for s in self.spans()
571+
if "db.operation.name" in s.attributes and "db.command.name" not in s.attributes
572+
]
573+
self.assertEqual(op_span.attributes["error.type"], op_span.attributes["exception.type"])
574+
self.assertEqual(op_span.attributes["error.type"], _qualified_name(type(ctx.exception)))
575+
562576
@async_client_context.require_failCommand_fail_point
563577
async def test_error_type_is_exception_class_name_for_connection_failure(self):
564578
# A closed connection produces no server reply, so error.type uses the class name.

‎test/test_otel.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,20 @@ def test_failure_records_exception_and_status_code(self):
559559
self.assertEqual(span.attributes["error.type"], span.attributes["db.response.status_code"])
560560
self.assertTrue(any(event.name == "exception" for event in span.events))
561561

562+
def test_operation_span_error_type_is_exception_class_name_for_server_error(self):
563+
client = self.rs_or_single_client(tracing={"enabled": True})
564+
self.exporter.clear()
565+
with self.assertRaises(OperationFailure) as ctx:
566+
client[self.db.name].command("thisCommandDoesNotExist")
567+
568+
(op_span,) = [
569+
s
570+
for s in self.spans()
571+
if "db.operation.name" in s.attributes and "db.command.name" not in s.attributes
572+
]
573+
self.assertEqual(op_span.attributes["error.type"], op_span.attributes["exception.type"])
574+
self.assertEqual(op_span.attributes["error.type"], _qualified_name(type(ctx.exception)))
575+
562576
@client_context.require_failCommand_fail_point
563577
def test_error_type_is_exception_class_name_for_connection_failure(self):
564578
# A closed connection produces no server reply, so error.type uses the class name.

0 commit comments

Comments
 (0)