Visitar URL original
PYTHON-6045 Trim the error.type comments and docstring · mongodb/mongo-python-driver@1a0330d · GitHub
Skip to content

Commit 1a0330d

Browse files
committed
PYTHON-6045 Trim the error.type comments and docstring
Cut each to the invariant a reader needs, dropping restatements of the code.
1 parent f6c5741 commit 1a0330d

3 files changed

Lines changed: 12 additions & 18 deletions

File tree

‎pymongo/_otel.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,9 @@ def _set_exception_attributes(span: Span, exc: BaseException) -> str:
414414
415415
``record_exception`` attaches these to an "exception" *event* only, but the
416416
spec requires them as span *attributes* too, for both command and operation
417-
spans. Formatting mirrors ``record_exception``. Returns the computed
418-
``exception.type`` value so callers (e.g. ``error.type``) can reuse it
419-
without recomputing.
417+
spans. Formatting mirrors ``record_exception``.
418+
419+
:return: The ``exception.type`` value.
420420
"""
421421
module = type(exc).__module__
422422
qualname = type(exc).__qualname__
@@ -443,12 +443,10 @@ def end_command_span_failure(
443443
exception_type = _set_exception_attributes(span, exc)
444444
code = failure.get("code")
445445
if code is not None:
446-
# Server error: error.type mirrors db.response.status_code, per spec.
447446
span.set_attribute("db.response.status_code", str(code))
448447
span.set_attribute("error.type", str(code))
449448
else:
450-
# Non-server error (e.g. network failure): fall back to the
451-
# exception's class name, since there's no server error code to report.
449+
# A network failure gets no server reply, so there is no code to report.
452450
span.set_attribute("error.type", exception_type)
453451
span.set_status(Status(StatusCode.ERROR, description=failure.get("errmsg")))
454452
finally:

‎test/asynchronous/test_otel.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,8 @@ async def test_failure_records_exception_and_status_code(self):
509509

510510
@async_client_context.require_failCommand_fail_point
511511
async def test_error_type_is_exception_class_name_for_connection_failure(self):
512-
# A closed connection produces no server reply, so there is no error
513-
# code to report: the spec falls back to the exception's class name.
512+
# A closed connection produces no server reply, so error.type falls back
513+
# to the exception's class name.
514514
client = await self.async_rs_or_single_client(tracing={"enabled": True}, retryReads=False)
515515
fail_command = {
516516
"configureFailPoint": "failCommand",
@@ -527,14 +527,12 @@ async def test_error_type_is_exception_class_name_for_connection_failure(self):
527527
attrs = spans[0].attributes
528528
self.assertNotIn("db.response.status_code", attrs)
529529
self.assertEqual(attrs["error.type"], _qualified_name(type(ctx.exception)))
530-
# error.type and exception.type carry the same value here, by design:
531-
# one is the span attribute, the other the exception event's.
530+
# error.type and exception.type carry the same value on this path.
532531
self.assertEqual(attrs["error.type"], attrs["exception.type"])
533532

534533
@async_client_context.require_failCommand_blockConnection
535534
async def test_error_type_is_exception_class_name_for_network_timeout(self):
536-
# socketTimeoutMS trips before the blocked command replies, so again
537-
# there is no server error code and error.type is the class name.
535+
# socketTimeoutMS trips before any reply, so again no server error code.
538536
client = await self.async_rs_or_single_client(
539537
tracing={"enabled": True}, socketTimeoutMS=200, retryReads=False
540538
)

‎test/test_otel.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,8 @@ def test_failure_records_exception_and_status_code(self):
509509

510510
@client_context.require_failCommand_fail_point
511511
def test_error_type_is_exception_class_name_for_connection_failure(self):
512-
# A closed connection produces no server reply, so there is no error
513-
# code to report: the spec falls back to the exception's class name.
512+
# A closed connection produces no server reply, so error.type falls back
513+
# to the exception's class name.
514514
client = self.rs_or_single_client(tracing={"enabled": True}, retryReads=False)
515515
fail_command = {
516516
"configureFailPoint": "failCommand",
@@ -527,14 +527,12 @@ def test_error_type_is_exception_class_name_for_connection_failure(self):
527527
attrs = spans[0].attributes
528528
self.assertNotIn("db.response.status_code", attrs)
529529
self.assertEqual(attrs["error.type"], _qualified_name(type(ctx.exception)))
530-
# error.type and exception.type carry the same value here, by design:
531-
# one is the span attribute, the other the exception event's.
530+
# error.type and exception.type carry the same value on this path.
532531
self.assertEqual(attrs["error.type"], attrs["exception.type"])
533532

534533
@client_context.require_failCommand_blockConnection
535534
def test_error_type_is_exception_class_name_for_network_timeout(self):
536-
# socketTimeoutMS trips before the blocked command replies, so again
537-
# there is no server error code and error.type is the class name.
535+
# socketTimeoutMS trips before any reply, so again no server error code.
538536
client = self.rs_or_single_client(
539537
tracing={"enabled": True}, socketTimeoutMS=200, retryReads=False
540538
)

0 commit comments

Comments
 (0)