From b720205e45fbdad235d1582d9651d957a5ef4080 Mon Sep 17 00:00:00 2001 From: Luiz Irber Date: Fri, 19 Jan 2024 21:45:26 -0800 Subject: [PATCH] fix(server): init sentry before the tokio runtime (#12) sentry docs recommend starting it before the tokio runtime --- Cargo.lock | 45 +++++++++++++++++++++++++-------------- Cargo.toml | 2 +- crates/server/Cargo.toml | 1 + crates/server/src/main.rs | 24 +++++++++++++++------ 4 files changed, 48 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0e0e0f5..80d93e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1307,6 +1307,7 @@ version = "0.1.0" dependencies = [ "axum", "clap", + "color-eyre", "sentry", "serde_json", "sourmash", @@ -2230,9 +2231,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "sentry" -version = "0.31.0" +version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c3d7f8bf7373e75222452fcdd9347d857452a92d0eec738f941bc4656c5b5df" +checksum = "234f6e133d27140ad5ea3b369a7665f7fbc060fe246f81d8168665b38c08b600" dependencies = [ "httpdate", "reqwest", @@ -2240,6 +2241,7 @@ dependencies = [ "sentry-backtrace", "sentry-contexts", "sentry-core", + "sentry-debug-images", "sentry-panic", "sentry-tower", "sentry-tracing", @@ -2250,9 +2252,9 @@ dependencies = [ [[package]] name = "sentry-backtrace" -version = "0.31.0" +version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03b7cdefbdca51f1146f0f24a3cb4ecb6428951f030ff5c720cfb5c60bd174c0" +checksum = "d89b6b53de06308dd5ac08934b597bcd72a9aae0c20bc3ab06da69cb34d468e3" dependencies = [ "backtrace", "once_cell", @@ -2262,9 +2264,9 @@ dependencies = [ [[package]] name = "sentry-contexts" -version = "0.31.0" +version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6af4cb29066e0e8df0cc3111211eb93543ccb09e1ccbe71de6d88b4bb459a2b1" +checksum = "0769b66763e59976cd5c0fd817dcd51ccce404de8bebac0cd0e886c55b0fffa8" dependencies = [ "hostname", "libc", @@ -2276,9 +2278,9 @@ dependencies = [ [[package]] name = "sentry-core" -version = "0.31.0" +version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e781b55761e47a60d1ff326ae8059de22b0e6b0cee68eab1c5912e4fb199a76" +checksum = "a1f954f1b89e8cd82576dc49bfab80304c9a6201343b4fe5c68c819f7a9bbed2" dependencies = [ "build_id", "findshlibs", @@ -2295,11 +2297,22 @@ dependencies = [ "uuid 1.3.2", ] +[[package]] +name = "sentry-debug-images" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8ddb9b6d43d251b41b792079218ef2d688bd88f01df454d338771cc146bde1a" +dependencies = [ + "findshlibs", + "once_cell", + "sentry-core", +] + [[package]] name = "sentry-panic" -version = "0.31.0" +version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e0b877981990d9e84ae6916df61993d188fdf76afb59521f0aeaf9b8e6d26d0" +checksum = "94dc2ab494362ad51308c7c19f44e9ab70e426a931621e4a05f378a1e74558c2" dependencies = [ "sentry-backtrace", "sentry-core", @@ -2307,9 +2320,9 @@ dependencies = [ [[package]] name = "sentry-tower" -version = "0.31.0" +version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e934c257597464ec8fb9067e44d29bd93d55056ef638931b46c80a3be8793562" +checksum = "9353d0ddceafd5e47376cd5741ddb78992b4953aa37110efe7cb357f92506107" dependencies = [ "http", "pin-project", @@ -2321,9 +2334,9 @@ dependencies = [ [[package]] name = "sentry-tracing" -version = "0.31.0" +version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4692bfc5bf69a8a41ccb0ce96612686eddb2406e32f7113f536efa15949af8" +checksum = "d0933cf65123955ddc6b95b10c73b3fdd2032a973768e072de1afd6fd2d80e3d" dependencies = [ "sentry-core", "tracing-core", @@ -2332,9 +2345,9 @@ dependencies = [ [[package]] name = "sentry-types" -version = "0.31.0" +version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d642a04657cc77d8de52ae7c6d93a15cb02284eb219344a89c1e2b26bbaf578c" +checksum = "85c53caf80cb1c6fcdf4d82b7bfff8477f50841e4caad7bf8e5e57a152b564cb" dependencies = [ "debugid", "getrandom", diff --git a/Cargo.toml b/Cargo.toml index 3e31117..2612056 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,5 +29,5 @@ tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt", "json"] } [profile.release] -debug = 1 +#debug = 2 #lto = true # Enable link-time optimization diff --git a/crates/server/Cargo.toml b/crates/server/Cargo.toml index a4b14ac..07ffea3 100644 --- a/crates/server/Cargo.toml +++ b/crates/server/Cargo.toml @@ -8,6 +8,7 @@ license = "AGPL" [dependencies] clap.workspace = true +color-eyre.workspace = true sourmash.workspace = true serde_json.workspace = true axum.workspace = true diff --git a/crates/server/src/main.rs b/crates/server/src/main.rs index 3943e98..76295bb 100644 --- a/crates/server/src/main.rs +++ b/crates/server/src/main.rs @@ -11,11 +11,13 @@ use axum::{ }; use sentry::integrations::tower::{NewSentryLayer, SentryHttpLayer}; use sentry::integrations::tracing as sentry_tracing; +use tokio::runtime::Runtime; use tower::{BoxError, ServiceBuilder}; use tower_http::{services::ServeDir, trace::TraceLayer}; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; use clap::Parser; +use color_eyre::eyre::Result; use sourmash::index::revindex::RevIndex; use sourmash::signature::{Signature, SigsTrait}; use sourmash::sketch::minhash::{max_hash_for_scaled, KmerMinHash}; @@ -54,8 +56,7 @@ struct Cli { threshold_bp: usize, } -#[tokio::main] -async fn main() { +fn main() -> Result<()> { let _guard = sentry::init(( std::env::var("SENTRY_DSN").expect("$SENTRY_DSN must be set"), sentry::ClientOptions { @@ -117,13 +118,22 @@ async fn main() { .into_inner(), ); - // Run our app with hyper + // Create the runtime + let rt = Runtime::new()?; + let addr = SocketAddr::from(([127, 0, 0, 1], opts.port)); tracing::debug!("listening on {}", addr); - axum::Server::bind(&addr) - .serve(app.into_make_service()) - .await - .unwrap(); + + // Spawn the root task + rt.block_on(async { + // Run our app with hyper + axum::Server::bind(&addr) + .serve(app.into_make_service()) + .await + .unwrap(); + }); + + Ok(()) } type SharedState = Arc;