summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/config.rs30
-rw-r--r--src/main.rs9
2 files changed, 20 insertions, 19 deletions
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<String>,
}
+pub struct Sentry(pub ClientInitGuard);
+
impl Configuration {
pub fn new() -> Result<Self, ConfigError> {
let mut cfg = config::Config::new();
cfg.merge(config::Environment::default())?;
cfg.try_into()
}
+}
+
+impl Sentry {
+ pub fn new() -> Result<Self, std::env::VarError> {
+ 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<ClientInitGuard> {
- 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.");
}
diff --git a/src/main.rs b/src/main.rs
index dac14e8..2a14629 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -8,7 +8,7 @@ mod models;
mod pagination;
mod routes;
-use crate::config::CONFIG;
+use crate::config::{CONFIG, SENTRY};
use axum::{
handler::Handler,
http::{header, Method, Request},
@@ -33,13 +33,6 @@ async fn main() {
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() {