28 releases (16 breaking)

0.22.0 Jan 13, 2021
0.21.0 Nov 12, 2020
0.20.1 Sep 15, 2020
0.19.0 Jun 18, 2020
0.2.0 Jul 21, 2018
Download history 325/week @ 2020-10-05 163/week @ 2020-10-12 156/week @ 2020-10-19 157/week @ 2020-10-26 131/week @ 2020-11-02 171/week @ 2020-11-09 187/week @ 2020-11-16 284/week @ 2020-11-23 248/week @ 2020-11-30 338/week @ 2020-12-07 219/week @ 2020-12-14 158/week @ 2020-12-21 277/week @ 2020-12-28 344/week @ 2021-01-04 336/week @ 2021-01-11 233/week @ 2021-01-18

960 downloads per month

Apache-2.0

120KB
2K SLoC

Sentry Rust SDK: sentry-actix

This crate adds a middleware for actix-web that captures errors and report them to Sentry.

To use this middleware just configure Sentry and then add it to your actix web app as a middleware. Because actix is generally working with non sendable objects and highly concurrent this middleware creates a new hub per request. As a result many of the sentry integrations such as breadcrumbs do not work unless you bind the actix hub.

Example

use std::env;
use std::io;

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())
}

#[actix_web::main]
async fn main() -> io::Result<()> {
    let _guard = sentry::init(());
    env::set_var("RUST_BACKTRACE", "1");

    HttpServer::new(|| {
        App::new()
            .wrap(sentry_actix::Sentry::new())
            .service(failing)
    })
    .bind("127.0.0.1:3001")?
    .run()
    .await?;

    Ok(())
}

Reusing the Hub

This integration will automatically update the current Hub instance. For example, the following will capture a message in the current request's Hub:

use sentry::Level;
sentry::capture_message("Something is not well", Level::Warning);

Resources

License: Apache-2.0

Dependencies

~21MB
~496K SLoC