Skip to content

fix: sentry-actix should not capture client errors #286

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 1 commit into from
Oct 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions sentry-actix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ where
};

// Response errors
if inner.capture_server_errors {
if inner.capture_server_errors && res.response().status().is_server_error() {
if let Some(e) = res.response().error() {
let event_id = hub.capture_error(e);

Expand Down Expand Up @@ -329,8 +329,6 @@ mod tests {
async fn test_explicit_events() {
let events = sentry::test::with_captured_events(|| {
block_on(async {
let test_hub = Hub::current();

let service = || {
// Current Hub should have no events
_assert_hub_no_events();
Expand All @@ -345,7 +343,7 @@ mod tests {

let mut app = init_service(
App::new()
.wrap(Sentry::builder().with_hub(test_hub).finish())
.wrap(Sentry::builder().with_hub(Hub::current()).finish())
.service(web::resource("/test").to(service)),
)
.await;
Expand Down Expand Up @@ -374,8 +372,6 @@ mod tests {
async fn test_response_errors() {
let events = sentry::test::with_captured_events(|| {
block_on(async {
let test_hub = Hub::current();

#[get("/test")]
async fn failing(_req: HttpRequest) -> Result<String, Error> {
// Current hub should have no events
Expand All @@ -386,7 +382,7 @@ mod tests {

let mut app = init_service(
App::new()
.wrap(Sentry::builder().with_hub(test_hub).finish())
.wrap(Sentry::builder().with_hub(Hub::current()).finish())
.service(failing),
)
.await;
Expand All @@ -411,4 +407,27 @@ mod tests {
assert_eq!(request.method, Some("GET".into()));
}
}

/// Ensures client errors (4xx) are not captured.
#[actix_rt::test]
async fn test_client_errors_discarded() {
let events = sentry::test::with_captured_events(|| {
block_on(async {
let service = || HttpResponse::NotFound();

let mut app = init_service(
App::new()
.wrap(Sentry::builder().with_hub(Hub::current()).finish())
.service(web::resource("/test").to(service)),
)
.await;

let req = TestRequest::get().uri("/test").to_request();
let res = call_service(&mut app, req).await;
assert!(res.status().is_client_error());
})
});

assert!(events.is_empty());
}
}