From d13f2d6a6d452970c019147cd95e4d27e79799fa Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 9 Jan 2019 14:59:56 -0800 Subject: wire up basic sentry error reporting --- rust/src/bin/fatcatd.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'rust/src/bin') diff --git a/rust/src/bin/fatcatd.rs b/rust/src/bin/fatcatd.rs index 34652105..388c6e61 100644 --- a/rust/src/bin/fatcatd.rs +++ b/rust/src/bin/fatcatd.rs @@ -12,7 +12,9 @@ use iron::middleware::AfterMiddleware; use iron::modifiers::RedirectRaw; use iron::{status, Chain, Iron, IronResult, Request, Response}; use iron_slog::{DefaultLogFormatter, LoggerMiddleware}; +use sentry::integrations::panic; use slog::{Drain, Logger}; +use std::env; // HTTP header middleware header! { (XClacksOverhead, "X-Clacks-Overhead") => [String] } @@ -38,12 +40,26 @@ fn main() -> Result<()> { ) .get_matches(); + dotenv::dotenv().ok(); + let decorator = slog_term::TermDecorator::new().build(); let drain = slog_term::CompactFormat::new(decorator).build().fuse(); let drain = slog_async::Async::new(drain).build().fuse(); let logger = Logger::root(drain, o!()); let formatter = DefaultLogFormatter; + // sentry exception handling + let sentry_dsn = env::var("SENTRY_DSN"); + let _guard = if let Ok(dsn) = sentry_dsn { + let client = sentry::init(dsn); + panic::register_panic_handler(); + info!(logger, "Sentry configured via DSN"); + Some(client) + } else { + info!(logger, "Sentry not configured"); + None + }; + let server = create_server()?; info!( logger, -- cgit v1.2.3