Skip to content

Commit 3901b32

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 3338459 commit 3901b32

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
@@ -411,9 +411,9 @@ def _set_exception_attributes(span: Span, exc: BaseException) -> str:
411411
412412
``record_exception`` attaches these to an "exception" *event* only, but the
413413
spec requires them as span *attributes* too, for both command and operation
414-
spans. Formatting mirrors ``record_exception``. Returns the computed
415-
``exception.type`` value so callers (e.g. ``error.type``) can reuse it
416-
without recomputing.
414+
spans. Formatting mirrors ``record_exception``.
415+
416+
:return: The ``exception.type`` value.
417417
"""
418418
module = type(exc).__module__
419419
qualname = type(exc).__qualname__
@@ -439,12 +439,10 @@ def end_command_span_failure(
439439
exception_type = _set_exception_attributes(span, exc)
440440
code = failure.get("code")
441441
if code is not None:
442-
# Server error: error.type mirrors db.response.status_code, per spec.
443442
span.set_attribute("db.response.status_code", str(code))
444443
span.set_attribute("error.type", str(code))
445444
else:
446-
# Non-server error (e.g. network failure): fall back to the
447-
# exception's class name, since there's no server error code to report.
445+
# A network failure gets no server reply, so there is no code to report.
448446
span.set_attribute("error.type", exception_type)
449447
span.set_status(Status(StatusCode.ERROR, description=failure.get("errmsg")))
450448
span.end()

‎test/asynchronous/test_otel.py‎

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

512512
@async_client_context.require_failCommand_fail_point
513513
async def test_error_type_is_exception_class_name_for_connection_failure(self):
514-
# A closed connection produces no server reply, so there is no error
515-
# code to report: the spec falls back to the exception's class name.
514+
# A closed connection produces no server reply, so error.type falls back
515+
# to the exception's class name.
516516
client = await self.async_rs_or_single_client(tracing={"enabled": True}, retryReads=False)
517517
fail_command = {
518518
"configureFailPoint": "failCommand",
@@ -529,14 +529,12 @@ async def test_error_type_is_exception_class_name_for_connection_failure(self):
529529
attrs = spans[0].attributes
530530
self.assertNotIn("db.response.status_code", attrs)
531531
self.assertEqual(attrs["error.type"], _qualified_name(type(ctx.exception)))
532-
# error.type and exception.type carry the same value here, by design:
533-
# one is the span attribute, the other the exception event's.
532+
# error.type and exception.type carry the same value on this path.
534533
self.assertEqual(attrs["error.type"], attrs["exception.type"])
535534

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

‎test/test_otel.py‎

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

512512
@client_context.require_failCommand_fail_point
513513
def test_error_type_is_exception_class_name_for_connection_failure(self):
514-
# A closed connection produces no server reply, so there is no error
515-
# code to report: the spec falls back to the exception's class name.
514+
# A closed connection produces no server reply, so error.type falls back
515+
# to the exception's class name.
516516
client = self.rs_or_single_client(tracing={"enabled": True}, retryReads=False)
517517
fail_command = {
518518
"configureFailPoint": "failCommand",
@@ -529,14 +529,12 @@ def test_error_type_is_exception_class_name_for_connection_failure(self):
529529
attrs = spans[0].attributes
530530
self.assertNotIn("db.response.status_code", attrs)
531531
self.assertEqual(attrs["error.type"], _qualified_name(type(ctx.exception)))
532-
# error.type and exception.type carry the same value here, by design:
533-
# one is the span attribute, the other the exception event's.
532+
# error.type and exception.type carry the same value on this path.
534533
self.assertEqual(attrs["error.type"], attrs["exception.type"])
535534

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

0 commit comments

Comments
 (0)