Skip to content

fix(api): downgrade client cancellation from error to warning#2158

Merged
dobrac merged 4 commits into
mainfrom
jk/downgrade-client-cancel-errors
Mar 18, 2026
Merged

fix(api): downgrade client cancellation from error to warning#2158
dobrac merged 4 commits into
mainfrom
jk/downgrade-client-cancel-errors

Conversation

@dobrac
Copy link
Copy Markdown
Contributor

@dobrac dobrac commented Mar 18, 2026

Summary

  • Detect context.Canceled in the logging middleware and OTEL tracing middleware to distinguish client disconnects from real server errors
  • Logging middleware now logs canceled requests at Warn instead of Error, even when the HTTP status is 5xx
  • OTEL tracing middleware sets a client.canceled=true span attribute instead of marking the span as an error status

Note

Medium Risk
Small change but it alters how 5xx requests are classified in logs and OpenTelemetry spans, which can impact alerting and error-rate dashboards if cancellation detection is wrong.

Overview
Adjusts request observability to distinguish client disconnects from server failures: the logging middleware no longer emits 5xx responses as Error when the request context is context.Canceled, and the OTEL tracing middleware avoids setting an error span status for canceled requests, instead tagging spans with client.canceled=true.

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

Comment thread packages/api/internal/middleware/otel/tracing/middleware.go Outdated
Comment thread packages/api/internal/middleware/otel/tracing/middleware.go Outdated
Comment thread packages/shared/pkg/middleware/logging.go Outdated
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 Outdated
@dobrac dobrac force-pushed the jk/downgrade-client-cancel-errors branch 2 times, most recently from 80d28a9 to c972f24 Compare March 18, 2026 11:45
When a client disconnects (user cancel or LB timeout), the request
context is canceled. Previously this was logged at Error level and
marked as an error span in OTEL traces, creating noise alongside
real server errors.

Now context.Canceled is detected in both the logging middleware and
the OTEL tracing middleware: log level is downgraded to Warn and
the span gets a client.canceled attribute instead of an error status.
@dobrac dobrac force-pushed the jk/downgrade-client-cancel-errors branch from c972f24 to 8a016ee Compare March 18, 2026 11:46
@dobrac dobrac merged commit 164f31a into main Mar 18, 2026
36 checks passed
@dobrac dobrac deleted the jk/downgrade-client-cancel-errors branch March 18, 2026 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants