diff --git a/sentry-actix/Cargo.toml b/sentry-actix/Cargo.toml index ae219084..197ef781 100644 --- a/sentry-actix/Cargo.toml +++ b/sentry-actix/Cargo.toml @@ -7,13 +7,14 @@ readme = "README.md" repository = "https://github.com/getsentry/sentry-rust" homepage = "https://sentry.io/welcome/" description = """ -Sentry client extension for actix-web 3. +Sentry client extension for actix-web 4. """ edition = "2018" [dependencies] sentry-core = { version = "0.23.0", path = "../sentry-core", default-features = false } -actix-web = { version = "3", default-features = false } +actix-service = "2.0" +actix-web = { version = "4.0.0-beta.10", default-features = false } futures-util = { version = "0.3.5", default-features = false } [dev-dependencies] diff --git a/sentry-actix/src/lib.rs b/sentry-actix/src/lib.rs index dfa2f61f..7db639ba 100644 --- a/sentry-actix/src/lib.rs +++ b/sentry-actix/src/lib.rs @@ -70,7 +70,6 @@ use std::pin::Pin; use std::sync::Arc; use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform}; -use actix_web::Error; use futures_util::future::{ok, Future, Ready}; use futures_util::FutureExt; @@ -150,14 +149,13 @@ impl Default for Sentry { } } -impl Transform for Sentry +impl Transform for Sentry where - S: Service, Error = Error>, + S: Service, Error = actix_web::Error>, S::Future: 'static, { - type Request = ServiceRequest; type Response = ServiceResponse; - type Error = Error; + type Error = actix_web::Error; type Transform = SentryMiddleware; type InitError = (); type Future = Ready>; @@ -176,24 +174,23 @@ pub struct SentryMiddleware { inner: Sentry, } -impl Service for SentryMiddleware +impl Service for SentryMiddleware where - S: Service, Error = Error>, + S: Service, Error = actix_web::Error>, S::Future: 'static, { - type Request = ServiceRequest; type Response = ServiceResponse; - type Error = Error; + type Error = actix_web::Error; type Future = Pin>>>; fn poll_ready( - &mut self, + &self, cx: &mut std::task::Context<'_>, ) -> std::task::Poll> { self.service.poll_ready(cx) } - fn call(&mut self, req: ServiceRequest) -> Self::Future { + fn call(&self, req: ServiceRequest) -> Self::Future { let inner = self.inner.clone(); let hub = Arc::new(Hub::new_from_top( inner.hub.clone().unwrap_or_else(Hub::main), @@ -347,7 +344,7 @@ mod tests { HttpResponse::Ok() }; - let mut app = init_service( + let app = init_service( App::new() .wrap(Sentry::builder().with_hub(Hub::current()).finish()) .service(web::resource("/test").to(service)), @@ -357,7 +354,7 @@ mod tests { // Call the service twice (sequentially) to ensure the middleware isn't sticky for _ in 0..2 { let req = TestRequest::get().uri("/test").to_request(); - let res = call_service(&mut app, req).await; + let res = call_service(&app, req).await; assert!(res.status().is_success()); } }) @@ -379,14 +376,14 @@ mod tests { let events = sentry::test::with_captured_events(|| { block_on(async { #[get("/test")] - async fn failing(_req: HttpRequest) -> Result { + async fn failing(_req: HttpRequest) -> Result { // Current hub should have no events _assert_hub_no_events(); Err(io::Error::new(io::ErrorKind::Other, "Test Error").into()) } - let mut app = init_service( + let app = init_service( App::new() .wrap(Sentry::builder().with_hub(Hub::current()).finish()) .service(failing), @@ -396,7 +393,7 @@ mod tests { // Call the service twice (sequentially) to ensure the middleware isn't sticky for _ in 0..2 { let req = TestRequest::get().uri("/test").to_request(); - let res = call_service(&mut app, req).await; + let res = call_service(&app, req).await; assert!(res.status().is_server_error()); } }) @@ -421,7 +418,7 @@ mod tests { block_on(async { let service = || HttpResponse::NotFound(); - let mut app = init_service( + let app = init_service( App::new() .wrap(Sentry::builder().with_hub(Hub::current()).finish()) .service(web::resource("/test").to(service)), @@ -429,7 +426,7 @@ mod tests { .await; let req = TestRequest::get().uri("/test").to_request(); - let res = call_service(&mut app, req).await; + let res = call_service(&app, req).await; assert!(res.status().is_client_error()); }) }); @@ -443,13 +440,15 @@ mod tests { let events = sentry::test::with_captured_events(|| { block_on(async { #[get("/test")] - async fn original_transaction(_req: HttpRequest) -> Result { + async fn original_transaction( + _req: HttpRequest, + ) -> Result { // Override transaction name sentry::configure_scope(|scope| scope.set_transaction(Some("new_transaction"))); Err(io::Error::new(io::ErrorKind::Other, "Test Error").into()) } - let mut app = init_service( + let app = init_service( App::new() .wrap(Sentry::builder().with_hub(Hub::current()).finish()) .service(original_transaction), @@ -457,7 +456,7 @@ mod tests { .await; let req = TestRequest::get().uri("/test").to_request(); - let res = call_service(&mut app, req).await; + let res = call_service(&app, req).await; assert!(res.status().is_server_error()); }) }); @@ -485,11 +484,11 @@ mod tests { let middleware = Sentry::builder().with_hub(Hub::current()).finish(); - let mut app = init_service(App::new().wrap(middleware).service(hello)).await; + let app = init_service(App::new().wrap(middleware).service(hello)).await; for _ in 0..5 { let req = TestRequest::get().uri("/").to_request(); - call_service(&mut app, req).await; + call_service(&app, req).await; } }) },