fix(api): record client cancellations as 499 in metrics#2159
Merged
Conversation
Follow-up to 164f31a - applies the same client cancellation handling to the metrics middleware. Cancelled requests are now recorded with http.status_code=499 (nginx convention for client-closed-request) and a client.canceled=true attribute, preventing them from inflating the 5xx error rate.
de52e0f to
66bf835
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: de52e0fc85
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
jakubno
approved these changes
Mar 18, 2026
Follow-up to 164f31a - applies client cancellation handling to the metrics and tracing middlewares. Cancelled requests are now recorded with http.status_code=499 (nginx convention for client-closed-request), preventing them from inflating the 5xx error rate. Also always records both a grouped status code (http.status_code, e.g. 400/500) and a granular one (http.status_code_granular, e.g. 404/499), removing the groupedStatus config toggle.
66bf835 to
dd5c2c7
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
ValentaTomas
pushed a commit
that referenced
this pull request
May 4, 2026
* fix(api): record client cancellations as 499 in metrics Follow-up to 5161c06 - applies the same client cancellation handling to the metrics middleware. Cancelled requests are now recorded with http.status_code=499 (nginx convention for client-closed-request) and a client.canceled=true attribute, preventing them from inflating the 5xx error rate. * fix(api): record client cancellations as 499 in metrics and traces Follow-up to 5161c06 - applies client cancellation handling to the metrics and tracing middlewares. Cancelled requests are now recorded with http.status_code=499 (nginx convention for client-closed-request), preventing them from inflating the 5xx error rate. Also always records both a grouped status code (http.status_code, e.g. 400/500) and a granular one (http.status_code_granular, e.g. 404/499), removing the groupedStatus config toggle. * fix(api): simplify tracing for client cancellations
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.

Summary
Follow-up to #2158 (164f31a) which downgraded client cancellation from error to warning in logging and tracing, but left the metrics middleware unchanged.
http.status_code=499(nginx convention for "client closed request before server responded") instead of the actual server-side status code (e.g. 500), preventing them from inflating the 5xx error ratehttp.status_code, e.g.400,500) and granular (http.status_code_granular, e.g.404,499) status code are now always recorded, removing the previousgroupedStatusconfig toggleNote
Low Risk
Low risk telemetry-only change, but it will shift HTTP status distributions by reclassifying canceled requests to 499 and changing metric attributes, which may affect alerts/dashboards.
Overview
Updates the OTEL metrics and tracing middleware to treat
context.Canceledrequests as HTTP499(client closed request) so they don’t inflate server error rates. Metrics now always emit both groupedhttp.status_code(e.g.,500) and a new granularhttp.status_code_granular(e.g.,499), removing the priorgroupedStatusconfiguration toggle.Written by Cursor Bugbot for commit 7c13b77. This will update automatically on new commits. Configure here.