Crates.io | sentry-actix |
lib.rs | sentry-actix |
version | |
source | src |
created_at | 2018-06-19 17:47:57.178724+00 |
updated_at | 2025-04-01 11:45:07.768211+00 |
description | Sentry client extension for actix-web 3. |
homepage | https://sentry.io/welcome/ |
repository | https://github.com/getsentry/sentry-rust |
max_upload_size | |
id | 70832 |
Cargo.toml error: | TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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.
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
})
}
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()
});
This integration will automatically create a new per-request Hub from the main Hub, and update the current Hub instance. For example, the following in the handler or in any of the subsequent middleware will capture a message in the current request's Hub:
sentry::capture_message("Something is not well", sentry::Level::Warning);
It is recommended to register the Sentry middleware as the last, i.e. the first to be executed when processing a request, so that the rest of the processing will run with the correct Hub.
License: MIT