fix: track HTTP status code errors in context for observability#1630
Merged
SamMorrowDrums merged 1 commit intomainfrom Dec 17, 2025
Merged
fix: track HTTP status code errors in context for observability#1630SamMorrowDrums merged 1 commit intomainfrom
SamMorrowDrums merged 1 commit intomainfrom
Conversation
Add NewGitHubAPIStatusErrorResponse helper function to properly track GitHub API errors when the API call succeeds but returns an unexpected HTTP status code (e.g., 404, 422, 500). Previously, these errors were returned via utils.NewToolResultError which bypasses the context-based error tracking used by the remote server's error_categorizer.go for observability metrics. This resulted in 100% tool call success rates in observability even when errors occurred. The fix adds a new helper function that: 1. Creates a synthetic error from the status code and response body 2. Records the error in context via NewGitHubAPIErrorResponse 3. Returns the MCP error result to the client Updated all tool files to use the new pattern for status code errors: - pullrequests.go: 12 fixes - repositories.go: 18 fixes - issues.go: 10 fixes - notifications.go: 6 fixes - projects.go: 5 fixes - search.go: 3 fixes - search_utils.go: 1 fix - gists.go: 4 fixes - code_scanning.go: 2 fixes - dependabot.go: 2 fixes - secret_scanning.go: 2 fixes - security_advisories.go: 4 fixes Total: ~69 error paths now properly tracked. Note: Parameter validation errors (RequiredParam failures) and internal I/O errors (io.ReadAll failures) intentionally continue to use utils.NewToolResultError as they are not GitHub API errors.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical observability gap where HTTP status code errors (e.g., 404, 422, 500) from successful GitHub API calls were not being tracked in context, resulting in falsely reported 100% tool call success rates. The solution introduces a new helper function NewGitHubAPIStatusErrorResponse that creates synthetic errors from status codes and response bodies, then records them in context for observability metrics.
Key changes:
- Added
NewGitHubAPIStatusErrorResponsehelper inpkg/errors/error.goto handle status code errors - Systematically updated ~69 error paths across 12 tool files to use the new helper
- Added comprehensive test coverage for the new function
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/errors/error.go | Added NewGitHubAPIStatusErrorResponse helper function to create synthetic errors from status codes and track them in context |
| pkg/errors/error_test.go | Added comprehensive test for the new helper function verifying MCP error result creation and context storage |
| pkg/github/pullrequests.go | Updated 12 HTTP status error paths to use NewGitHubAPIStatusErrorResponse for proper error tracking |
| pkg/github/repositories.go | Updated 18 HTTP status error paths to use NewGitHubAPIStatusErrorResponse for proper error tracking |
| pkg/github/issues.go | Updated 10 HTTP status error paths to use NewGitHubAPIStatusErrorResponse for proper error tracking |
| pkg/github/notifications.go | Updated 6 HTTP status error paths to use NewGitHubAPIStatusErrorResponse for proper error tracking |
| pkg/github/projects.go | Updated 5 HTTP status error paths to use NewGitHubAPIStatusErrorResponse for proper error tracking |
| pkg/github/search.go | Updated 3 HTTP status error paths to use NewGitHubAPIStatusErrorResponse for proper error tracking |
| pkg/github/search_utils.go | Updated 1 HTTP status error path to use NewGitHubAPIStatusErrorResponse for proper error tracking |
| pkg/github/gists.go | Updated 4 HTTP status error paths to use NewGitHubAPIStatusErrorResponse for proper error tracking |
| pkg/github/code_scanning.go | Updated 2 HTTP status error paths to use NewGitHubAPIStatusErrorResponse; removed unused fmt import |
| pkg/github/dependabot.go | Updated 2 HTTP status error paths to use NewGitHubAPIStatusErrorResponse for proper error tracking |
| pkg/github/secret_scanning.go | Updated 2 HTTP status error paths to use NewGitHubAPIStatusErrorResponse for proper error tracking |
| pkg/github/security_advisories.go | Updated 4 HTTP status error paths to use NewGitHubAPIStatusErrorResponse for proper error tracking |
ed3f9dc to
e1bc004
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The remote server's
error_categorizer.gouses context to extract GitHub API errors for observability metrics. However, when API calls succeed but return unexpected HTTP status codes (e.g., 404, 422, 500), the errors were returned viautils.NewToolResultErrorwhich bypasses the context-based error tracking.This resulted in 100% tool call success rates in observability even when errors occurred.
Root Cause
There are three categories of errors in the tool handlers:
Parameter validation errors (e.g.,
RequiredParamfailures) - These correctly useutils.NewToolResultErroras they are user input errors, not GitHub API errors.GitHub API client errors (when
err != nilafter API call) - These mostly useghErrors.NewGitHubAPIErrorResponseand are tracked correctly.HTTP status code errors (when API succeeds but returns non-2xx) - These were using
utils.NewToolResultErrorand were NOT being tracked.Solution
Add a new helper function
NewGitHubAPIStatusErrorResponsethat:NewGitHubAPIErrorResponseThen systematically updated all tool files to use this new pattern.
Changes
New Function in
pkg/errors/error.goFiles Updated
Relation to Existing PRs
This PR addresses the bulk of the error tracking issue that PRs #1566 and #1570 are also addressing:
NewGitHubGraphQLErrorToCtxand fixes a few issues.go errorsGitHubRawAPIErrortype for raw client errors and fixes GetFileContentsThis PR focuses on the ~69 HTTP status code error paths across all tool files that were not being tracked. After this PR merges:
Testing
NewGitHubAPIStatusErrorResponseNotes
utils.NewToolResultError- they are user input errors, not API errorsio.ReadAllfailures) continue to useutils.NewToolResultErrorFromErr- they are not GitHub API errorsresp(GitHub Response) andctxare tracked