Learn about using Sentry with Actix Web.

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

To use this middleware, configure Sentry then add it to your actix web app as a middleware. Because actix is generally working with non sendable objects and is 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.

Note: Macros like #[tokio::main] and #[actix_web::main] are not supported. The Sentry client must be initialized before the async runtime is started so that all threads are correctly connected to the Hub.

In your Cargo.toml:

actix-web = "4.3.1"
sentry = "0.34.0"
sentry-actix = "0.34.0"

And your Rust code:
use std::io;

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

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!(),
    std::env::set_var("RUST_BACKTRACE", "1");

    actix_web::rt::System::new().block_on(async {
        HttpServer::new(|| {


When using the actix integration, a new per-request Hub will be created from the main Hub, and will be set automatically as the current Hub (Hub::current()). No manual intervention in needed.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").