From b5ad26f8833b5a4039a168cf83c6f6b75dfaecbf Mon Sep 17 00:00:00 2001 From: m1sk9 Date: Thu, 4 Jan 2024 00:01:51 +0900 Subject: [PATCH 1/2] deps: add sentry --- Cargo.lock | 169 ++++++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 13 +++++ 2 files changed, 181 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 93e602d..d4bdb0b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -704,6 +704,16 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" +[[package]] +name = "debugid" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef552e6f588e446098f6ba40d89ac146c8c7b64aade83c051ee00bb5d2bc18d" +dependencies = [ + "serde", + "uuid", +] + [[package]] name = "deranged" version = "0.3.11" @@ -901,6 +911,18 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "findshlibs" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40b9e59cd0f7e0806cca4be089683ecb6434e602038df21fe6bf6711b2f07f64" +dependencies = [ + "cc", + "lazy_static", + "libc", + "winapi", +] + [[package]] name = "finl_unicode" version = "1.2.0" @@ -1297,7 +1319,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.4.10", + "socket2 0.5.5", "tokio", "tower-service", "tracing", @@ -1896,6 +1918,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "os_info" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "006e42d5b888366f1880eda20371fedde764ed2213dc8496f49622fa0c99cd5e" +dependencies = [ + "log", + "serde", + "winapi", +] + [[package]] name = "overload" version = "0.1.1" @@ -2505,6 +2538,7 @@ dependencies = [ "rand", "regex", "reqwest", + "sentry", "sequoia-openpgp", "serde", "serde_json", @@ -2585,6 +2619,115 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +[[package]] +name = "sentry" +version = "0.32.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab18211f62fb890f27c9bb04861f76e4be35e4c2fcbfc2d98afa37aadebb16f1" +dependencies = [ + "httpdate", + "reqwest", + "rustls", + "sentry-backtrace", + "sentry-contexts", + "sentry-core", + "sentry-debug-images", + "sentry-panic", + "sentry-tracing", + "tokio", + "ureq", + "webpki-roots", +] + +[[package]] +name = "sentry-backtrace" +version = "0.32.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf018ff7d5ce5b23165a9cbfee60b270a55ae219bc9eebef2a3b6039356dd7e5" +dependencies = [ + "backtrace", + "once_cell", + "regex", + "sentry-core", +] + +[[package]] +name = "sentry-contexts" +version = "0.32.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d934df6f9a17b8c15b829860d9d6d39e78126b5b970b365ccbd817bc0fe82c9" +dependencies = [ + "hostname", + "libc", + "os_info", + "rustc_version 0.4.0", + "sentry-core", + "uname", +] + +[[package]] +name = "sentry-core" +version = "0.32.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e362d3fb1c5de5124bf1681086eaca7adf6a8c4283a7e1545359c729f9128ff" +dependencies = [ + "once_cell", + "rand", + "sentry-types", + "serde", + "serde_json", +] + +[[package]] +name = "sentry-debug-images" +version = "0.32.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8bca420d75d9e7a8e54a4806bf4fa8a7e9a804e8f2ff05c7c80234168c6ca66" +dependencies = [ + "findshlibs", + "once_cell", + "sentry-core", +] + +[[package]] +name = "sentry-panic" +version = "0.32.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0224e7a8e2bd8a32d96804acb8243d6d6e073fed55618afbdabae8249a964d8" +dependencies = [ + "sentry-backtrace", + "sentry-core", +] + +[[package]] +name = "sentry-tracing" +version = "0.32.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "087bed8c616d176a9c6b662a8155e5f23b40dc9e1fa96d0bd5fb56e8636a9275" +dependencies = [ + "sentry-backtrace", + "sentry-core", + "tracing-core", + "tracing-subscriber", +] + +[[package]] +name = "sentry-types" +version = "0.32.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb4f0e37945b7a8ce7faebc310af92442e2d7c5aa7ef5b42fe6daa98ee133f65" +dependencies = [ + "debugid", + "hex", + "rand", + "serde", + "serde_json", + "thiserror", + "time", + "url", + "uuid", +] + [[package]] name = "sequoia-openpgp" version = "1.17.0" @@ -3382,6 +3525,15 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "uname" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b72f89f0ca32e4db1c04e2a72f5345d59796d4866a1ee0609084569f73683dc8" +dependencies = [ + "libc", +] + [[package]] name = "unicase" version = "2.7.0" @@ -3424,6 +3576,21 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" +[[package]] +name = "ureq" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cdd25c339e200129fe4de81451814e5228c9b771d57378817d6117cc2b3f97" +dependencies = [ + "base64 0.21.5", + "log", + "once_cell", + "rustls", + "rustls-webpki", + "url", + "webpki-roots", +] + [[package]] name = "url" version = "2.5.0" diff --git a/Cargo.toml b/Cargo.toml index 6817820..d32362c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" From c4c75b7fa0f64849b51a807bb5be69c62f4b5abf Mon Sep 17 00:00:00 2001 From: m1sk9 Date: Thu, 4 Jan 2024 00:02:01 +0900 Subject: [PATCH 2/2] feat: enable sentry --- src/main.rs | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 58bca60..240bc21 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 { + 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")]