Skip to content

Commit a04b44a

Browse files
authored
Merge pull request #84 from approvers/feat/sentry
feat: sentry の追加
2 parents c9bb0c1 + c4c75b7 commit a04b44a

File tree

3 files changed

+214
-4
lines changed

3 files changed

+214
-4
lines changed

Cargo.lock

+168-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+13
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,18 @@ features = [
9898
"ab_glyph",
9999
]
100100

101+
102+
[dependencies.sentry]
103+
version = "0.32"
104+
default-features = false
105+
features = [
106+
"backtrace",
107+
"contexts",
108+
"panic",
109+
"debug-images",
110+
"reqwest",
111+
"rustls",
112+
]
113+
101114
[dev-dependencies]
102115
pretty_assertions = "1"

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)