Skip to content

Commit

Permalink
GH-66 # Set last_scans_sample_rate through env var
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo-C committed Aug 11, 2024
1 parent 01a30a8 commit 01612f5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::env;
use std::sync::Arc;
use sentry::TransactionContext;
use ::rocket_sentry::RocketSentry;
Expand Down Expand Up @@ -35,13 +36,18 @@ async fn main() -> Result<(), rocket::Error> {
.figment()
.extract_inner::<f32>("sentry_traces_sample_rate")
.unwrap_or(1.);
let last_scans_sample_rate_default: f32 = 0.;
let last_scans_sample_rate = match env::var("LAST_SCAN_SAMPLE_RATE"){
Ok(value) => value.parse::<f32>().unwrap_or(last_scans_sample_rate_default),
Err(_) => last_scans_sample_rate_default,
};
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
last_scans_sample_rate
}
},
_ => default_rate,
Expand Down

0 comments on commit 01612f5

Please sign in to comment.