39 releases (23 breaking)

Uses new Rust 2021

new 0.29.2 Jan 25, 2023
0.29.1 Dec 1, 2022
0.29.0 Nov 17, 2022
0.27.0 Jun 20, 2022
0.2.0 Jul 21, 2018

#26 in HTTP server

Download history 2337/week @ 2022-10-07 1914/week @ 2022-10-14 2474/week @ 2022-10-21 2327/week @ 2022-10-28 2579/week @ 2022-11-04 2414/week @ 2022-11-11 2503/week @ 2022-11-18 2308/week @ 2022-11-25 2658/week @ 2022-12-02 2446/week @ 2022-12-09 2584/week @ 2022-12-16 1909/week @ 2022-12-23 1786/week @ 2022-12-30 2583/week @ 2023-01-06 2549/week @ 2023-01-13 2687/week @ 2023-01-20

9,946 downloads per month

Apache-2.0

190KB
3.5K SLoC

Sentry

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::io;

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

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

fn main() -> io::Result<()> {
    let _guard = sentry::init(sentry::ClientOptions {
        release: sentry::release_name!(),
        ..Default::default()
    });
    std::env::set_var("RUST_BACKTRACE", "1");

    let runtime = tokio::runtime::Builder::new_multi_thread()
        .enable_all()
        .build()?;
    runtime.block_on(async move {
        HttpServer::new(|| {
            App::new()
                .wrap(sentry_actix::Sentry::new())
                .service(failing)
        })
        .bind("127.0.0.1:3001")?
        .run()
        .await
    })
}

Using Release Health

The actix middleware will automatically start a new session for each request when auto_session_tracking is enabled and the client is configured to use SessionMode::Request.

let _sentry = sentry::init(sentry::ClientOptions {
    release: sentry::release_name!(),
    session_mode: sentry::SessionMode::Request,
    auto_session_tracking: true,
    ..Default::default()
});

Reusing the Hub

This integration will automatically create a new per-request Hub from the main Hub, and update the current Hub instance. For example, the following will capture a message in the current request's Hub:

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

Resources

License: Apache-2.0

Dependencies

~15–22MB
~506K SLoC