Skip to content

PYTHON-6045 Add error.type OpenTelemetry command span attribute - #3000

Draft
blink1073 wants to merge 4 commits into
PYTHON-5947-otel-4-getmorefrom
PYTHON-5947-otel-5-error-type
Draft

PYTHON-6045 Add error.type OpenTelemetry command span attribute#3000
blink1073 wants to merge 4 commits into
PYTHON-5947-otel-4-getmorefrom
PYTHON-5947-otel-5-error-type

Conversation

@blink1073

@blink1073 blink1073 commented Aug 20, 2026

Copy link
Copy Markdown
Member

PYTHON-6045

Fifth in the OpenTelemetry stack, on top of the four PRs splitting #2964. Base is PYTHON-5947-otel-4-getmore.

Branch Contents
1 PYTHON-5947-otel-1-operations operation spans
2 PYTHON-5947-otel-2-transactions transaction spans
3 PYTHON-5947-otel-3-unified unified runner and vendored fixtures
4 PYTHON-5947-otel-4-getmore getMore spans
5 PYTHON-5947-otel-5-error-type error.type command span attribute (this PR)

Implements error.type on command spans, specified by DRIVERS-3617 (mongodb/specifications#1974). OpenTelemetry backends group and alert on span attributes, so an error class carried only by the exception event cannot be queried at the span level.

Changes in this PR

  • end_command_span_failure sets error.type to the server error code when the reply carries one, otherwise to the exception's qualified class name.
  • _set_exception_attributes returns the computed exception.type so the fallback reuses it.
  • Operation spans omit error.type, because an operation can succeed through a retry even when a command failed.
  • Synced the new error_type.json spec fixture.

Test Plan

  • Spec fixture error_type.json covers a server error, where error.type matches db.response.status_code, and a closed connection, where it falls back to the class name.
  • New unit tests cover the fallback for ConnectionFailure and NetworkTimeout. Both fail if the fallback branch is removed.
  • Extended the existing server-error test to assert error.type mirrors db.response.status_code.
  • Full otel suite passes. just lint and just typing are clean.
  • Evergreen otel-rhel8 patch #10898 passed with 0 failed tasks.

Checklist

Checklist for Author

  • Did you update the changelog (if necessary)?
  • Is there test coverage?
  • Is any followup work tracked in a JIRA ticket? If so, add link(s).

Checklist for Reviewer

  • Does the title of the PR reference a JIRA Ticket?
  • Do you fully understand the implementation? (Would you be comfortable explaining how this code works to someone else?)
  • Is all relevant documentation (README or docstring) updated?

@blink1073
blink1073 force-pushed the PYTHON-5947-otel-5-error-type branch from 5583231 to d161a7f Compare August 21, 2026 15:28
@blink1073
blink1073 force-pushed the PYTHON-5947-otel-5-error-type branch from d161a7f to 3901b32 Compare August 21, 2026 15:51
@blink1073
blink1073 force-pushed the PYTHON-5947-otel-5-error-type branch from 3901b32 to 8a91f4e Compare August 21, 2026 16:02
@blink1073
blink1073 force-pushed the PYTHON-5947-otel-5-error-type branch 2 times, most recently from 7020b94 to e3b52c5 Compare August 23, 2026 22:29
@blink1073
blink1073 force-pushed the PYTHON-5947-otel-5-error-type branch from e3b52c5 to 5ecc46c Compare August 26, 2026 16:54
@blink1073
blink1073 force-pushed the PYTHON-5947-otel-5-error-type branch from 5ecc46c to bf59e7f Compare August 26, 2026 19:43
@blink1073
blink1073 force-pushed the PYTHON-5947-otel-5-error-type branch from bf59e7f to 1c28013 Compare September 1, 2026 10:27
@blink1073
blink1073 force-pushed the PYTHON-5947-otel-5-error-type branch from 1c28013 to 19b45bc Compare September 1, 2026 10:48
@blink1073
blink1073 force-pushed the PYTHON-5947-otel-5-error-type branch from 19b45bc to 8451fa3 Compare September 1, 2026 11:01
@blink1073
blink1073 force-pushed the PYTHON-5947-otel-5-error-type branch from 8451fa3 to 5a9f0aa Compare September 1, 2026 16:00
Emit error.type on command spans, mirroring db.response.status_code for
server errors and falling back to the exception class name otherwise.
Operation spans deliberately do not carry error.type, per the spec.

Syncs the new open-telemetry error_type.json spec fixture (both the
server-error and non-server-error cases).
Covers the two non-server-error paths where there is no server error
code to mirror: a closed connection (ConnectionFailure) and a socket
timeout (NetworkTimeout). Both assert error.type is the exception's
qualified class name and that db.response.status_code is absent.
Cut each to the invariant a reader needs, dropping restatements of the code.
@blink1073
blink1073 force-pushed the PYTHON-5947-otel-5-error-type branch from 5a9f0aa to 1a0330d Compare September 1, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant