From 5f84cc97e51deec241b47a501a391def33811a09 Mon Sep 17 00:00:00 2001 From: Hugo-C Date: Wed, 3 Jul 2024 00:17:29 +0200 Subject: [PATCH] GH-62 # Bump API dependencies --- Cargo.lock | 140 ++++++---------------------------------------------- Cargo.toml | 2 +- src/main.rs | 28 ++++++++++- 3 files changed, 43 insertions(+), 127 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0251a3e..a2067bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1254,7 +1254,7 @@ dependencies = [ "rocket_db_pools", "rstest", "rust_jarm", - "sentry 0.32.3", + "sentry", "serde", "tempfile", ] @@ -2049,7 +2049,7 @@ dependencies = [ "figment", "log", "rocket", - "sentry 0.34.0", + "sentry", "serde", ] @@ -2306,25 +2306,6 @@ version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" -[[package]] -name = "sentry" -version = "0.32.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00421ed8fa0c995f07cde48ba6c89e80f2b312f74ff637326f392fbfd23abe02" -dependencies = [ - "httpdate", - "native-tls", - "reqwest", - "sentry-backtrace 0.32.3", - "sentry-contexts 0.32.3", - "sentry-core 0.32.3", - "sentry-debug-images 0.32.3", - "sentry-panic 0.32.3", - "sentry-tracing 0.32.3", - "tokio", - "ureq", -] - [[package]] name = "sentry" version = "0.34.0" @@ -2334,28 +2315,16 @@ dependencies = [ "httpdate", "native-tls", "reqwest", - "sentry-backtrace 0.34.0", - "sentry-contexts 0.34.0", - "sentry-core 0.34.0", - "sentry-debug-images 0.34.0", - "sentry-panic 0.34.0", - "sentry-tracing 0.34.0", + "sentry-backtrace", + "sentry-contexts", + "sentry-core", + "sentry-debug-images", + "sentry-panic", + "sentry-tracing", "tokio", "ureq", ] -[[package]] -name = "sentry-backtrace" -version = "0.32.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a79194074f34b0cbe5dd33896e5928bbc6ab63a889bd9df2264af5acb186921e" -dependencies = [ - "backtrace", - "once_cell", - "regex", - "sentry-core 0.32.3", -] - [[package]] name = "sentry-backtrace" version = "0.34.0" @@ -2365,21 +2334,7 @@ dependencies = [ "backtrace", "once_cell", "regex", - "sentry-core 0.34.0", -] - -[[package]] -name = "sentry-contexts" -version = "0.32.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eba8870c5dba2bfd9db25c75574a11429f6b95957b0a78ac02e2970dd7a5249a" -dependencies = [ - "hostname", - "libc", - "os_info", - "rustc_version", - "sentry-core 0.32.3", - "uname", + "sentry-core", ] [[package]] @@ -2392,23 +2347,10 @@ dependencies = [ "libc", "os_info", "rustc_version", - "sentry-core 0.34.0", + "sentry-core", "uname", ] -[[package]] -name = "sentry-core" -version = "0.32.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46a75011ea1c0d5c46e9e57df03ce81f5c7f0a9e199086334a1f9c0a541e0826" -dependencies = [ - "once_cell", - "rand", - "sentry-types 0.32.3", - "serde", - "serde_json", -] - [[package]] name = "sentry-core" version = "0.34.0" @@ -2417,22 +2359,11 @@ checksum = "161283cfe8e99c8f6f236a402b9ccf726b201f365988b5bb637ebca0abbd4a30" dependencies = [ "once_cell", "rand", - "sentry-types 0.34.0", + "sentry-types", "serde", "serde_json", ] -[[package]] -name = "sentry-debug-images" -version = "0.32.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ec2a486336559414ab66548da610da5e9626863c3c4ffca07d88f7dc71c8de8" -dependencies = [ - "findshlibs", - "once_cell", - "sentry-core 0.32.3", -] - [[package]] name = "sentry-debug-images" version = "0.34.0" @@ -2441,17 +2372,7 @@ checksum = "8fc6b25e945fcaa5e97c43faee0267eebda9f18d4b09a251775d8fef1086238a" dependencies = [ "findshlibs", "once_cell", - "sentry-core 0.34.0", -] - -[[package]] -name = "sentry-panic" -version = "0.32.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2eaa3ecfa3c8750c78dcfd4637cfa2598b95b52897ed184b4dc77fcf7d95060d" -dependencies = [ - "sentry-backtrace 0.32.3", - "sentry-core 0.32.3", + "sentry-core", ] [[package]] @@ -2460,20 +2381,8 @@ version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc74f229c7186dd971a9491ffcbe7883544aa064d1589bd30b83fb856cd22d63" dependencies = [ - "sentry-backtrace 0.34.0", - "sentry-core 0.34.0", -] - -[[package]] -name = "sentry-tracing" -version = "0.32.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f715932bf369a61b7256687c6f0554141b7ce097287e30e3f7ed6e9de82498fe" -dependencies = [ - "sentry-backtrace 0.32.3", - "sentry-core 0.32.3", - "tracing-core", - "tracing-subscriber", + "sentry-backtrace", + "sentry-core", ] [[package]] @@ -2482,29 +2391,12 @@ version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd3c5faf2103cd01eeda779ea439b68c4ee15adcdb16600836e97feafab362ec" dependencies = [ - "sentry-backtrace 0.34.0", - "sentry-core 0.34.0", + "sentry-backtrace", + "sentry-core", "tracing-core", "tracing-subscriber", ] -[[package]] -name = "sentry-types" -version = "0.32.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4519c900ce734f7a0eb7aba0869dfb225a7af8820634a7dd51449e3b093cfb7c" -dependencies = [ - "debugid", - "hex", - "rand", - "serde", - "serde_json", - "thiserror", - "time", - "url", - "uuid", -] - [[package]] name = "sentry-types" version = "0.34.0" diff --git a/Cargo.toml b/Cargo.toml index 57017c7..7268113 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ lazy_static = "1.4" regex = "1.7" csv = "1.3" openssl = { version = "~0.10.55", features = ["vendored"] } # Required for sentry -sentry = "0.32" +sentry = "^0.34" rocket-sentry = "0.18" redis = "0.25" log = "0.4" diff --git a/src/main.rs b/src/main.rs index 370127e..29e571d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; +use sentry::TransactionContext; use ::rocket_sentry::RocketSentry; use env_logger::Env; use jarm_online::build_rocket; @@ -27,9 +29,31 @@ impl Fairing for CORS { #[rocket::main] async fn main() -> Result<(), rocket::Error> { env_logger::Builder::from_env(Env::default().default_filter_or("info")).init(); - build_rocket() + let rocket_instance = build_rocket(); + // Get the default configured sample rate from `Rocket.toml` + let default_rate = rocket_instance + .figment() + .extract_inner::("sentry_traces_sample_rate") + .unwrap_or(1.); + let traces_sampler = move |ctx: &TransactionContext| -> f32 { + match ctx.name() { + "GET /last-scans" => { + if default_rate == 0. { + 0. // Allow to disable Sentry completely + } else { + 0.0001 + } + }, + _ => default_rate, + } + }; + let rocket_sentry = RocketSentry::builder() + .traces_sampler(Arc::new(traces_sampler)) + .build(); + + rocket_instance .attach(CORS) - .attach(RocketSentry::fairing()) + .attach(rocket_sentry) .launch() .await?; Ok(())