Skip to content

fix(api): record client cancellations as 499 in metrics#2159

Merged
jakubno merged 3 commits into
mainfrom
fix/metrics-client-cancellation
Mar 18, 2026
Merged

fix(api): record client cancellations as 499 in metrics#2159
jakubno merged 3 commits into
mainfrom
fix/metrics-client-cancellation

Conversation

@dobrac
Copy link
Copy Markdown
Contributor

@dobrac dobrac commented Mar 18, 2026

Summary

Follow-up to #2158 (164f31a) which downgraded client cancellation from error to warning in logging and tracing, but left the metrics middleware unchanged.

  • Client-cancelled requests are now recorded with 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 rate
  • Both a grouped (http.status_code, e.g. 400, 500) and granular (http.status_code_granular, e.g. 404, 499) status code are now always recorded, removing the previous groupedStatus config toggle

Note

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.Canceled requests as HTTP 499 (client closed request) so they don’t inflate server error rates. Metrics now always emit both grouped http.status_code (e.g., 500) and a new granular http.status_code_granular (e.g., 499), removing the prior groupedStatus configuration toggle.

Written by Cursor Bugbot for commit 7c13b77. This will update automatically on new commits. Configure here.

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.
@dobrac dobrac added the improvement Improvement for current functionality label Mar 18, 2026
@dobrac dobrac marked this pull request as draft March 18, 2026 16:17
@dobrac dobrac marked this pull request as ready for review March 18, 2026 16:24
@dobrac dobrac force-pushed the fix/metrics-client-cancellation branch from de52e0f to 66bf835 Compare March 18, 2026 16:25
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment thread packages/api/internal/middleware/otel/metrics/config.go
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.
@dobrac dobrac force-pushed the fix/metrics-client-cancellation branch from 66bf835 to dd5c2c7 Compare March 18, 2026 16:28
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment thread packages/api/internal/middleware/otel/tracing/middleware.go
@jakubno jakubno merged commit d9e4f7c into main Mar 18, 2026
36 checks passed
@jakubno jakubno deleted the fix/metrics-client-cancellation branch March 18, 2026 17:15
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Improvement for current functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants