Skip to content

Commit

Permalink
Upgrade actix-web and actix-service
Browse files Browse the repository at this point in the history
The latest actix-service is now stable and actix-web has since had some
additional work added to the beta branch. This adds those new
dependencies.
  • Loading branch information
jplatte authored and Kbowman committed Nov 12, 2021
1 parent bf71bf4 commit 6dbf966
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
7 changes: 4 additions & 3 deletions sentry-actix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
sentry-core = { version = "0.23.0", path = "../sentry-core", default-features = false, features = ["client"] }
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]
Expand Down
45 changes: 22 additions & 23 deletions sentry-actix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -150,14 +149,13 @@ impl Default for Sentry {
}
}

impl<S, B> Transform<S> for Sentry
impl<S, B> Transform<S, ServiceRequest> for Sentry
where
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = actix_web::Error>,
S::Future: 'static,
{
type Request = ServiceRequest;
type Response = ServiceResponse<B>;
type Error = Error;
type Error = actix_web::Error;
type Transform = SentryMiddleware<S>;
type InitError = ();
type Future = Ready<Result<Self::Transform, Self::InitError>>;
Expand All @@ -176,24 +174,23 @@ pub struct SentryMiddleware<S> {
inner: Sentry,
}

impl<S, B> Service for SentryMiddleware<S>
impl<S, B> Service<ServiceRequest> for SentryMiddleware<S>
where
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = actix_web::Error>,
S::Future: 'static,
{
type Request = ServiceRequest;
type Response = ServiceResponse<B>;
type Error = Error;
type Error = actix_web::Error;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>>>>;

fn poll_ready(
&mut self,
&self,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Result<(), Self::Error>> {
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),
Expand Down Expand Up @@ -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)),
Expand All @@ -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());
}
})
Expand All @@ -379,14 +376,14 @@ mod tests {
let events = sentry::test::with_captured_events(|| {
block_on(async {
#[get("/test")]
async fn failing(_req: HttpRequest) -> Result<String, Error> {
async fn failing(_req: HttpRequest) -> Result<String, actix_web::Error> {
// 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),
Expand All @@ -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());
}
})
Expand All @@ -421,15 +418,15 @@ 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)),
)
.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());
})
});
Expand All @@ -443,21 +440,23 @@ mod tests {
let events = sentry::test::with_captured_events(|| {
block_on(async {
#[get("/test")]
async fn original_transaction(_req: HttpRequest) -> Result<String, Error> {
async fn original_transaction(
_req: HttpRequest,
) -> Result<String, actix_web::Error> {
// 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),
)
.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());
})
});
Expand Down Expand Up @@ -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;
}
})
},
Expand Down

0 comments on commit 6dbf966

Please sign in to comment.