[][src]Crate 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.


extern crate actix_web;
extern crate sentry;
extern crate sentry_actix;

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

use actix_web::{server, App, Error, HttpRequest};
use sentry_actix::SentryMiddleware;

fn failing(_req: &HttpRequest) -> Result<String, Error> {
    Err(io::Error::new(io::ErrorKind::Other, "An error happens here").into())

fn main() {
    let _guard = sentry::init("https://public@sentry.io/1234");
    env::set_var("RUST_BACKTRACE", "1");

    server::new(|| {
            .resource("/", |r| r.f(failing))

Reusing the Hub

If you use this integration the Hub::current() returned hub is typically the wrong one. To get the request specific one you need to use the ActixWebHubExt trait:

use sentry::{Hub, Level};
use sentry_actix::ActixWebHubExt;

let hub = Hub::from_request(req);
hub.capture_message("Something is not well", Level::Warning);

The hub can also be made current:

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);



Reports certain failures to sentry.


A helper construct that can be used to reconfigure and build the middleware.



Hub extensions for actix.



Utility function that takes an actix error and reports it to the default hub.