Skip to content

Commit c4c75b7

Browse files
m1sk9kawaemon
authored andcommitted
feat: enable sentry
1 parent b5ad26f commit c4c75b7

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

src/main.rs

+33-3
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,50 @@ use {
1212
},
1313
anyhow::{Context as _, Result},
1414
bot::meigen::MeigenBot,
15+
sentry::ClientInitGuard,
1516
};
1617

1718
assert_one_feature!("discord_client", "console_client");
1819
assert_one_feature!("mongo_db", "memory_db");
1920
assert_one_feature!("plot_plotters", "plot_matplotlib");
2021

21-
#[tokio::main]
22-
async fn main() -> Result<()> {
22+
fn setup_sentry() -> Option<ClientInitGuard> {
23+
let Ok(sentry_dsn) = env_var("SENTRY_DSN") else {
24+
#[cfg(not(debug_assertions))]
25+
panic!("SENTRY_DSN is not set");
26+
#[cfg(debug_assertions)]
27+
return None;
28+
};
29+
30+
let guard = sentry::init((
31+
sentry_dsn,
32+
sentry::ClientOptions {
33+
release: sentry::release_name!(),
34+
..Default::default()
35+
},
36+
));
37+
38+
tracing::info!("sentry initialized");
39+
40+
Some(guard)
41+
}
42+
43+
fn main() -> Result<()> {
2344
dotenv::dotenv().ok();
2445

2546
let use_ansi = env_var("NO_COLOR").is_err();
26-
2747
tracing_subscriber::fmt().with_ansi(use_ansi).init();
2848

49+
let _guard = setup_sentry();
50+
51+
tokio::runtime::Builder::new_multi_thread()
52+
.enable_all()
53+
.build()
54+
.unwrap()
55+
.block_on(async_main())
56+
}
57+
58+
async fn async_main() -> Result<()> {
2959
#[cfg(feature = "memory_db")]
3060
let local_db = crate::db::mem::MemoryDB::new();
3161
#[cfg(feature = "memory_db")]

0 commit comments

Comments
 (0)