Skip to content

Commit

Permalink
Merge pull request #84 from approvers/feat/sentry
Browse files Browse the repository at this point in the history
feat: sentry の追加
  • Loading branch information
kawaemon authored Jan 5, 2024
2 parents c9bb0c1 + c4c75b7 commit a04b44a
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 4 deletions.
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

0 comments on commit a04b44a

Please sign in to comment.