Skip to content

Conversation

@prestonvasquez
Copy link
Member

@prestonvasquez prestonvasquez commented Nov 18, 2025

GODRIVER-3690

Summary

Add an ErrorCodesFrom function that can be used to parse server error codes from an arbitrary Go error.

Background

Would be convenient to get server status codes without caller taking a dependency on the experimental API. For example, OpenTelemetry needs to include db.response.status.code for otelmongo: open-telemetry/opentelemetry-go-contrib#7983 (comment)

An alternative to this design would be to put Codes on event.CommandFailedEvent. Suggest we forgo this solution for two reasons:

  1. It breaks unkeyed composite literals for event.CommandFailedEvent
  2. There may be non-event cases where users would want to validate for error codes.

Copilot AI review requested due to automatic review settings November 18, 2025 01:13
@prestonvasquez prestonvasquez requested a review from a team as a code owner November 18, 2025 01:13
@prestonvasquez prestonvasquez marked this pull request as draft November 18, 2025 01:13
@prestonvasquez prestonvasquez removed the request for review from qingyang-hu November 18, 2025 01:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR extends the CommandFailedEvent structure to include error codes, addressing GODRIVER-3690. The change enables users to access error codes directly from command failure events without parsing the error themselves.

Key changes:

  • Added a Codes field to CommandFailedEvent to expose error codes
  • Implemented errorCodes() helper function to extract codes from driver errors
  • Added test coverage for the new field

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
event/monitoring.go Added Codes field to CommandFailedEvent structure
x/mongo/driver/operation.go Populates the new Codes field when publishing failed events; removed blank line
x/mongo/driver/errors.go Implemented errorCodes() function to extract error codes from driver errors
mongo/errors.go Refactored variable declarations to use var() block (style change)
internal/integration/clam_prose_test.go Added test case for CommandFailedEvent.Codes; removed blank line

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mongodb-drivers-pr-bot
Copy link
Contributor

mongodb-drivers-pr-bot bot commented Nov 18, 2025

🧪 Performance Results

Commit SHA: 58198cf

The following benchmark tests for version 692f82f467740700079be35b had statistically significant changes (i.e., |z-score| > 1.96):

Benchmark Measurement % Change Patch Value Stable Region H-Score Z-Score
BenchmarkSingleFindOneByID total_mem_allocs -11.9079 1459913.0000 Avg: 1657257.8103
Med: 1669065.0000
Stdev: 81069.6183
0.7813 -2.4343
BenchmarkSingleFindOneByID total_time_seconds -11.4412 1.0176 Avg: 1.1490
Med: 1.1563
Stdev: 0.0479
0.7968 -2.7428
BenchmarkSingleFindOneByID total_bytes_allocated -11.2001 90986584.0000 Avg: 102462432.1034
Med: 103155352.0000
Stdev: 4991197.0878
0.7671 -2.2992
BenchmarkSingleRunCommand total_time_seconds 8.3702 1.2104 Avg: 1.1169
Med: 1.1186
Stdev: 0.0345
0.7940 2.7075
BenchmarkBSONDeepDocumentDecoding ops_per_second_med 5.8161 17717.9305 Avg: 16744.0773
Med: 16716.6774
Stdev: 239.4284
0.8714 4.0674
BenchmarkBSONFullDocumentDecoding ops_per_second_med 5.6616 15343.3065 Avg: 14521.1791
Med: 14555.6170
Stdev: 216.9976
0.8569 3.7886
BenchmarkBSONFullDocumentDecoding total_bytes_allocated 4.9841 427742920.0000 Avg: 407436087.2381
Med: 408022784.0000
Stdev: 6922950.6374
0.8143 2.9333
BenchmarkBSONFullDocumentDecoding total_mem_allocs 4.9519 10335551.0000 Avg: 9847892.2857
Med: 9862458.0000
Stdev: 166742.1443
0.8137 2.9246
BenchmarkBSONDeepDocumentDecoding ops_per_second_max 4.9432 18174.2181 Avg: 17318.1506
Med: 17213.7779
Stdev: 256.4410
0.8582 3.3383
BenchmarkBSONDeepDocumentDecoding ns_per_op -4.9370 60201.0000 Avg: 63327.4762
Med: 63071.0000
Stdev: 763.1367
0.8651 -4.0969
BenchmarkBSONDeepDocumentDecoding total_mem_allocs 4.7851 13787238.0000 Avg: 13157634.9524
Med: 13200636.0000
Stdev: 146890.2456
0.8716 4.2862
BenchmarkBSONDeepDocumentDecoding total_bytes_allocated 4.7748 299505816.0000 Avg: 285856726.4762
Med: 286791096.0000
Stdev: 3182806.7075
0.8717 4.2884
BenchmarkBSONFlatDocumentDecoding ops_per_second_med 4.7571 21633.7833 Avg: 20651.3861
Med: 20667.5623
Stdev: 316.4221
0.8222 3.1047
BenchmarkSmallDocInsertOne total_time_seconds 4.6694 1.2393 Avg: 1.1840
Med: 1.1847
Stdev: 0.0241
0.7741 2.2913
BenchmarkBSONFullDocumentEncoding total_bytes_allocated 4.3892 277681592.0000 Avg: 266005972.1905
Med: 265760472.0000
Stdev: 2860049.8147
0.8634 4.0823
BenchmarkBSONFullDocumentDecoding ops_per_second_max 4.3712 15790.3048 Avg: 15128.9905
Med: 15148.3019
Stdev: 110.2808
0.9085 5.9966
BenchmarkBSONFullDocumentEncoding total_mem_allocs 4.3633 1604646.0000 Avg: 1537557.7143
Med: 1536447.0000
Stdev: 16638.8122
0.8618 4.0320
BenchmarkBSONFullDocumentDecoding ns_per_op -4.3421 71136.0000 Avg: 74365.0000
Med: 74288.0000
Stdev: 1380.3074
0.7688 -2.3393
BenchmarkBSONFlatDocumentDecoding ops_per_second_max 4.2399 22468.3758 Avg: 21554.4943
Med: 21614.6115
Stdev: 255.1400
0.8464 3.5819
BenchmarkBSONFullDocumentEncoding ops_per_second_med 4.1247 48090.7954 Avg: 46185.7692
Med: 46121.2065
Stdev: 611.4650
0.8233 3.1155
BenchmarkBSONFlatDocumentDecoding total_mem_allocs 3.8585 10970425.0000 Avg: 10562852.8571
Med: 10623830.0000
Stdev: 187322.1349
0.7495 2.1758
BenchmarkBSONFlatDocumentDecoding total_bytes_allocated 3.8484 431406120.0000 Avg: 415419257.5238
Med: 417811120.0000
Stdev: 7353265.9170
0.7493 2.1741
BenchmarkBSONFlatDocumentDecoding ns_per_op -3.8243 50251.0000 Avg: 52249.1905
Med: 52061.0000
Stdev: 902.0325
0.7497 -2.2152
BenchmarkBSONFullDocumentEncoding ns_per_op -3.2246 22586.0000 Avg: 23338.5714
Med: 23383.0000
Stdev: 311.5620
0.7721 -2.4155
BenchmarkBSONFullDocumentEncoding ops_per_second_max 2.8283 48902.1468 Avg: 47557.1119
Med: 47415.8369
Stdev: 547.9332
0.7737 2.4547
BenchmarkMultiFindMany ops_per_second_max 1.4548 4310344.8276 Avg: 4248536.7696
Med: 4255319.1489
Stdev: 27973.7336
0.7655 2.2095
BenchmarkBSONDeepDocumentEncoding allocated_bytes_per_op -0.1374 2140.0000 Avg: 2142.9444
Med: 2143.0000
Stdev: 1.3921
0.7432 -2.1151
BenchmarkBSONFullDocumentDecoding allocated_bytes_per_op 0.0297 25329.0000 Avg: 25321.4762
Med: 25321.0000
Stdev: 3.2034
0.8594 2.3487
BenchmarkBSONFlatDocumentDecoding allocated_bytes_per_op -0.0082 18051.0000 Avg: 18052.4762
Med: 18052.0000
Stdev: 0.6796
0.7819 -2.1720
BenchmarkBSONDeepDocumentDecoding allocated_bytes_per_op -0.0079 15098.0000 Avg: 15099.1905
Med: 15099.0000
Stdev: 0.5118
0.8095 -2.3262

For a comprehensive view of all microbenchmark results for this PR's commit, please check out the Evergreen perf task for this patch.

@mongodb-drivers-pr-bot
Copy link
Contributor

mongodb-drivers-pr-bot bot commented Nov 18, 2025

API Change Report

./v2/mongo

compatible changes

ErrorCodesFrom: added

@prestonvasquez prestonvasquez force-pushed the feature/godriver-3690-extend-event-failures-with-error-codes branch 2 times, most recently from 3b7f589 to 63d4781 Compare December 3, 2025 00:20
@prestonvasquez prestonvasquez force-pushed the feature/godriver-3690-extend-event-failures-with-error-codes branch from 63d4781 to 58198cf Compare December 3, 2025 00:23
@prestonvasquez prestonvasquez added review-priority-normal Medium Priority PR for Review: within 1 business day feature labels Dec 3, 2025
@prestonvasquez prestonvasquez changed the title (POC) GODRIVER-3690 Extend CommandFailedEvent with error codes GODRIVER-3690 Add ErrorCodesFrom to the mongo package Dec 3, 2025
@prestonvasquez prestonvasquez marked this pull request as ready for review December 3, 2025 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature review-priority-normal Medium Priority PR for Review: within 1 business day

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant