Skip to content
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

feat: actix-web 3 support #282

Merged
merged 6 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Code review changes
  • Loading branch information
aramperes committed Oct 19, 2020
commit f2122026763e655147164906e1756fc49306f171
16 changes: 12 additions & 4 deletions sentry-actix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,20 @@ such as breadcrumbs do not work unless you bind the actix hub.
use std::env;
use std::io;

use actix_web::{App, Error, get, HttpRequest, HttpServer};
use actix_web::{get, App, Error, HttpRequest, HttpServer};
use sentry::Level;

#[get("/")]
async fn failing(_req: HttpRequest) -> Result<String, Error> {
Err(io::Error::new(io::ErrorKind::Other, "An error happens here").into())
}

#[get("/hello")]
async fn hello_world(_req: HttpRequest) -> Result<String, Error> {
sentry::capture_message("Something is not well", Level::Warning);
Ok("Hello World".into())
}

#[actix_web::main]
async fn main() -> io::Result<()> {
let _guard = sentry::init(());
Expand All @@ -36,10 +43,11 @@ async fn main() -> io::Result<()> {
App::new()
.wrap(sentry_actix::Sentry::new())
.service(failing)
.service(hello_world)
})
.bind("127.0.0.1:3001")?
.run()
.await?;
.bind("127.0.0.1:3001")?
.run()
.await?;

Ok(())
}
Expand Down
14 changes: 5 additions & 9 deletions sentry-actix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//! use std::io;
//!
//! use actix_web::{get, App, Error, HttpRequest, HttpServer};
//! use sentry::Level;
//!
//! #[get("/")]
//! async fn failing(_req: HttpRequest) -> Result<String, Error> {
Expand All @@ -21,7 +22,7 @@
//!
//! #[actix_web::main]
//! async fn main() -> io::Result<()> {
//! let _guard = sentry::init("https://public@sentry.io/1234");
//! let _guard = sentry::init(());
//! env::set_var("RUST_BACKTRACE", "1");
//!
//! HttpServer::new(|| {
Expand Down Expand Up @@ -186,15 +187,13 @@ where

fn call(&mut self, req: ServiceRequest) -> Self::Future {
let inner = self.inner.clone();
let hub = inner
.hub
.clone()
.unwrap_or_else(|| Arc::new(Hub::new_from_top(Hub::main())));
let hub = Arc::new(Hub::new_from_top(
inner.hub.clone().unwrap_or_else(Hub::main),
));
let client = hub.client();
let with_pii = client
.as_ref()
.map_or(false, |x| x.options().send_default_pii);
let guard = hub.push_scope();

let (tx, sentry_req) = sentry_request_from_http(&req, with_pii);
hub.configure_scope(|scope| {
Expand Down Expand Up @@ -231,9 +230,6 @@ where
}
}

// Move the guard into the future and keep it from dropping until now
drop(guard);

Ok(res)
}
.boxed_local()
Expand Down