feat: add Sentry integration

Davide Polonio 2022-05-31 11:53:49 +02:00
parent c02c390a6d
commit 72856dbb74
2 changed files with 20 additions and 0 deletions

View File

@ -11,3 +11,4 @@ log = "0.4.17"
pretty_env_logger = "0.4.0"
tokio = { version = "1.18.2", features = ["rt-multi-thread", "macros"] }
rspotify = { version = "0.11.5", features = ["default"]}
sentry = "0.26.0"

View File

@ -1,3 +1,5 @@
use sentry::ClientInitGuard;
use std::env;
use teloxide::prelude::*;
use crate::spotify::{PlayableKind, TrackInfo};
@ -16,6 +18,23 @@ async fn main() {
teloxide::enable_logging!();
log::info!("Starting Songlify...");
let mut _guard: ClientInitGuard;
match env::var("SENTRY_DSN") {
Ok(sentry_dsn) => {
log::debug!("Sentry DSN found, enabling error reporting");
_guard = sentry::init((
sentry_dsn,
sentry::ClientOptions {
release: sentry::release_name!(),
..Default::default()
},
));
}
Err(_) => {
log::warn!("No sentry DSN set, errors will not be reported. Use SENTRY_DSN env variable if you want to set error reporting")
}
}
let bot = Bot::from_env().auto_send();
teloxide::repl(bot, |message: Message, bot: AutoSend<Bot>| async move {
let text = message.text().and_then(spotify::get_entry_kind);