diff options
| author | Santo Cariotti <santo@dcariotti.me> | 2022-09-27 20:24:21 +0000 |
|---|---|---|
| committer | Santo Cariotti <santo@dcariotti.me> | 2022-09-27 20:24:21 +0000 |
| commit | c1b842bf8b439dd01da4c86b5a24fe198ac73bab (patch) | |
| tree | 7974779ca0e1b0b82ecb304e3163a87269fc1e3e /src | |
| parent | 842edd5a75a091a58ea04b6f4d2ef7cf0b0285ea (diff) | |
Add Sentry
Diffstat (limited to 'src')
| -rw-r--r-- | src/config.rs | 15 | ||||
| -rw-r--r-- | src/main.rs | 8 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs index 0d266bf..b86d018 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,5 +1,6 @@ pub use config::ConfigError; use lazy_static::lazy_static; +use sentry::ClientInitGuard; use serde::Deserialize; #[derive(Deserialize)] @@ -11,6 +12,7 @@ pub struct Configuration { pub database_url: String, pub jwt_secret: String, pub allowed_host: String, + pub sentry_dsn: Option<String>, } impl Configuration { @@ -19,6 +21,19 @@ impl Configuration { cfg.merge(config::Environment::default())?; cfg.try_into() } + + pub fn set_sentry_guard(&self) -> Option<ClientInitGuard> { + match &self.sentry_dsn { + Some(dsn) => Some(sentry::init(( + dsn.clone(), + sentry::ClientOptions { + release: sentry::release_name!(), + ..Default::default() + }, + ))), + None => None, + } + } } lazy_static! { diff --git a/src/main.rs b/src/main.rs index b13be75..dac14e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,6 +32,14 @@ async fn main() { let app = create_app().await; let host = &CONFIG.allowed_host; + + match CONFIG.set_sentry_guard() { + Some(_) => {} + None => { + tracing::error!("Sentry not configured."); + } + }; + let addr = match host.parse::<SocketAddr>() { Ok(addr) => addr, Err(_) => match host.to_socket_addrs() { |
