From 6128a983f23a52138bc6cd84625246013b6097fb Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Mon, 3 Oct 2022 21:33:56 +0200 Subject: fix(sentry): keep connection open --- src/config.rs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs index b86d018..2898c81 100644 --- a/src/config.rs +++ b/src/config.rs @@ -12,30 +12,38 @@ pub struct Configuration { pub database_url: String, pub jwt_secret: String, pub allowed_host: String, - pub sentry_dsn: Option, } +pub struct Sentry(pub ClientInitGuard); + impl Configuration { pub fn new() -> Result { let mut cfg = config::Config::new(); cfg.merge(config::Environment::default())?; cfg.try_into() } +} + +impl Sentry { + pub fn new() -> Result { + match std::env::var("SENTRY_DSN") { + Ok(dsn) => { + let guard = sentry::init(( + dsn.clone(), + sentry::ClientOptions { + release: sentry::release_name!(), + ..Default::default() + }, + )); - pub fn set_sentry_guard(&self) -> Option { - match &self.sentry_dsn { - Some(dsn) => Some(sentry::init(( - dsn.clone(), - sentry::ClientOptions { - release: sentry::release_name!(), - ..Default::default() - }, - ))), - None => None, + Ok(Self(guard)) + } + Err(e) => Err(e), } } } lazy_static! { pub static ref CONFIG: Configuration = Configuration::new().expect("Config can be loaded"); + pub static ref SENTRY: Sentry = Sentry::new().expect("Sentry not configured."); } -- cgit v1.2.3-71-g8e6c