Skip to content

fix(actix): capture only server errors #877

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

Merged
merged 5 commits into from
Aug 6, 2025
Merged

Conversation

lcian
Copy link
Member

@lcian lcian commented Jul 31, 2025

Before this change, if a middleware processing the request after the Sentry one returned an error, we would capture it unconditionally.
With this change, we capture it only if it's a server error.
(note that the behavior was correct for responses returned by services (i.e. request handler, not middleware), as at line 373 we check if it's a server error).

This is one of the possible ways to tackle this, and I think this is the one that makes most sense for the following reasons:

  • Client errors could be spammy and don't usually provide much value to the user of Sentry.
  • Capturing errors can be expensive when attaching stack traces.
  • Better experience for new users that won't be surprised by this unintended behavior.

It must be said that there is a small possibility that someone misses this in the changelog who was actually relying on these errors to show up in Sentry.

Close #876

Copy link

codecov bot commented Jul 31, 2025

Codecov Report

❌ Patch coverage is 85.71429% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.29%. Comparing base (c29c01f) to head (28d59cf).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #877      +/-   ##
==========================================
+ Coverage   73.13%   73.29%   +0.16%     
==========================================
  Files          64       64              
  Lines        7366     7407      +41     
==========================================
+ Hits         5387     5429      +42     
+ Misses       1979     1978       -1     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lcian lcian marked this pull request as ready for review August 1, 2025 11:54
let req = TestRequest::get().uri("/test").to_request();
let res = app.call(req).await;
assert!(res.is_err());
assert!(res.unwrap_err().error_response().status().is_client_error());
Copy link
Member

Choose a reason for hiding this comment

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

[nit] I would check the exact status code, not just that it is a client error here

let req = TestRequest::get().uri("/test").to_request();
let res = app.call(req).await;
assert!(res.is_err());
assert!(res.unwrap_err().error_response().status().is_server_error());
Copy link
Member

Choose a reason for hiding this comment

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

[nit] also would check exact status code here

@szokeasaurusrex
Copy link
Member

looks good, couple of small (mostly optional) suggestions

@lcian lcian merged commit cd933d3 into master Aug 6, 2025
19 checks passed
@lcian lcian deleted the lcian/fix/actix-server-errors branch August 6, 2025 12:50
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.

Don't capture client errors in Actix Web integration
3 participants