Skip to content

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

Draft
blink1073 wants to merge 2 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 2 commits into
PYTHON-5947-otel-4-getmorefrom
PYTHON-5947-otel-5-error-type

Conversation

@blink1073

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 the error.type command span attribute specified by DRIVERS-3617 (mongodb/specifications#1974). error.type is the span-level dimension OpenTelemetry backends group and alert on; carried only as the exception event's exception.type, error class cannot be aggregated on.

Changes in this PR

  • end_command_span_failure sets error.type on command spans: the server error code when one is present (mirroring db.response.status_code), otherwise the exception's qualified class name.
  • _set_exception_attributes returns the computed exception.type so the fallback reuses it.
  • Operation spans deliberately omit error.type, per the spec: an operation can succeed via retry even when an underlying command failed.
  • Synced the new error_type.json spec fixture.

Test Plan

  • Spec fixture test/open_telemetry/operation/error_type.json: server error (error.type matches db.response.status_code) and closed connection (db.response.status_code absent, error.type is the class name). Both assert the operation span has no error.type.
  • Unit tests for the class-name fallback: ConnectionFailure and NetworkTimeout. Verified 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: 103 passed, 1 skipped (unrelated mapReduce deprecation). just lint and just typing clean.
  • Evergreen otel-rhel8: #10898 — success, 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?

Implements DRIVERS-3617: 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.
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