feat: add Sentry integration

0.3.x
Davide Polonio 2022-05-31 11:53:49 +02:00
parent c02c390a6d
commit 540c306483
2 changed files with 21 additions and 1 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "songlify" name = "songlify"
version = "0.3.1" version = "0.3.2"
edition = "2018" edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -11,3 +11,4 @@ log = "0.4.17"
pretty_env_logger = "0.4.0" pretty_env_logger = "0.4.0"
tokio = { version = "1.18.2", features = ["rt-multi-thread", "macros"] } tokio = { version = "1.18.2", features = ["rt-multi-thread", "macros"] }
rspotify = { version = "0.11.5", features = ["default"]} 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 teloxide::prelude::*;
use crate::spotify::{PlayableKind, TrackInfo}; use crate::spotify::{PlayableKind, TrackInfo};
@ -16,6 +18,23 @@ async fn main() {
teloxide::enable_logging!(); teloxide::enable_logging!();
log::info!("Starting Songlify..."); 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(); let bot = Bot::from_env().auto_send();
teloxide::repl(bot, |message: Message, bot: AutoSend<Bot>| async move { teloxide::repl(bot, |message: Message, bot: AutoSend<Bot>| async move {
let text = message.text().and_then(spotify::get_entry_kind); let text = message.text().and_then(spotify::get_entry_kind);