-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix: track HTTP status code errors in context for observability #1630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
There was a problem hiding this 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 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
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