Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sentry の追加 #84

Merged
merged 2 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 168 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,18 @@ features = [
"ab_glyph",
]


[dependencies.sentry]
version = "0.32"
default-features = false
features = [
"backtrace",
"contexts",
"panic",
"debug-images",
"reqwest",
"rustls",
]

[dev-dependencies]
pretty_assertions = "1"
36 changes: 33 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,50 @@ use {
},
anyhow::{Context as _, Result},
bot::meigen::MeigenBot,
sentry::ClientInitGuard,
};

assert_one_feature!("discord_client", "console_client");
assert_one_feature!("mongo_db", "memory_db");
assert_one_feature!("plot_plotters", "plot_matplotlib");

#[tokio::main]
async fn main() -> Result<()> {
fn setup_sentry() -> Option<ClientInitGuard> {
let Ok(sentry_dsn) = env_var("SENTRY_DSN") else {
#[cfg(not(debug_assertions))]
panic!("SENTRY_DSN is not set");
#[cfg(debug_assertions)]
return None;
};

let guard = sentry::init((
sentry_dsn,
sentry::ClientOptions {
release: sentry::release_name!(),
..Default::default()
},
));

tracing::info!("sentry initialized");

Some(guard)
}

fn main() -> Result<()> {
dotenv::dotenv().ok();

let use_ansi = env_var("NO_COLOR").is_err();

tracing_subscriber::fmt().with_ansi(use_ansi).init();

let _guard = setup_sentry();

tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap()
.block_on(async_main())
}

async fn async_main() -> Result<()> {
#[cfg(feature = "memory_db")]
let local_db = crate::db::mem::MemoryDB::new();
#[cfg(feature = "memory_db")]
Expand Down
Loading