mirror of
https://github.com/actix/actix-website
synced 2024-11-23 16:31:08 +01:00
First pass at Sentry.
This commit is contained in:
parent
650c66b64a
commit
5ca7b6dc83
@ -20,47 +20,16 @@ initialized and configured and the [sentry-actix middleware](https://crates.io/c
|
||||
needs to be added. Additionally it makes sense to also register the panic handler
|
||||
to be informed about hard panics.
|
||||
|
||||
```rust
|
||||
extern crate sentry;
|
||||
extern crate sentry_actix;
|
||||
|
||||
use sentry_actix::SentryMiddleware;
|
||||
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
sentry::init("SENTRY_DSN_GOES_HERE");
|
||||
env::set_var("RUST_BACKTRACE", "1");
|
||||
sentry::integrations::panic::register_panic_handler();
|
||||
|
||||
let mut app = App::with_state(state)
|
||||
.middleware(SentryMiddleware::new())
|
||||
// ...
|
||||
}
|
||||
```
|
||||
{{< include-example example="sentry" file="main.rs" section="middleware" >}}
|
||||
|
||||
# Reusing the Hub
|
||||
|
||||
If you use this integration the default sentry hub (`Hub::current()`) is typically the wrong one.
|
||||
To get the request specific one you need to use the `ActixWebHubExt` trait:
|
||||
|
||||
```rust
|
||||
use sentry::{Hub, Level};
|
||||
use sentry_actix::ActixWebHubExt;
|
||||
|
||||
let hub = Hub::from_request(req);
|
||||
hub.capture_message("Something is not well", Level::Warning);
|
||||
```
|
||||
{{< include-example example="sentry" file="main.rs" section="hub" >}}
|
||||
|
||||
The hub can also be made current for the duration of a call. Then `Hub::current()` works correctly
|
||||
until the end of the `run` block.
|
||||
|
||||
```rust
|
||||
use sentry::{Hub, Level};
|
||||
use sentry_actix::ActixWebHubExt;
|
||||
|
||||
let hub = Hub::from_request(req);
|
||||
Hub::run(hub, || {
|
||||
sentry::capture_message("Something is not well", Level::Warning);
|
||||
});
|
||||
```
|
||||
{{< include-example example="sentry" file="main.rs" section="hub2" >}}
|
||||
|
@ -27,4 +27,5 @@ exclude = [
|
||||
"http20",
|
||||
"databases",
|
||||
"og_databases",
|
||||
"sentry",
|
||||
]
|
||||
|
10
examples/sentry/Cargo.toml
Normal file
10
examples/sentry/Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "sentry"
|
||||
version = "0.1.0"
|
||||
authors = ["Cameron Dershem <cameron@pinkhatbeard.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "1.0"
|
||||
sentry-actix = "0.15"
|
||||
sentry = "0.15"
|
36
examples/sentry/src/main.rs
Normal file
36
examples/sentry/src/main.rs
Normal file
@ -0,0 +1,36 @@
|
||||
// <middleware>
|
||||
// use actix_web::{web, App, HttpResponse};
|
||||
// use sentry;
|
||||
// use sentry_actix::SentryMiddleware;
|
||||
|
||||
// use std::env;
|
||||
|
||||
// fn main() {
|
||||
// sentry::init("SENTRY_DSN_GOES_HERE");
|
||||
// env::set_var("RUST_BACKTRACE", "1");
|
||||
// sentry::integrations::panic::register_panic_handler();
|
||||
|
||||
// let mut app = App::new()
|
||||
// // .data(state)
|
||||
// .wrap(SentryMiddleware::new())
|
||||
// .route("/", web::get().to(|| HttpResponse::Ok()));
|
||||
// }
|
||||
// </middleware>
|
||||
|
||||
// <hub>
|
||||
// use sentry::{Hub, Level};
|
||||
// use sentry_actix::ActixWebHubExt;
|
||||
|
||||
// let hub = Hub::from_request(req);
|
||||
// hub.capture_message("Something is not well", Level::Warning);
|
||||
// // </hub>
|
||||
|
||||
// // <hub2>
|
||||
// use sentry::{Hub, Level};
|
||||
// use sentry_actix::ActixWebHubExt;
|
||||
|
||||
// let hub = Hub::from_request(req);
|
||||
// Hub::run(hub, || {
|
||||
// sentry::capture_message("Something is not well", Level::Warning);
|
||||
// });
|
||||
// </hub2>
|
Loading…
Reference in New Issue
Block a user