From 8a046059af20564193eae30e996eb8e48362acbd Mon Sep 17 00:00:00 2001 From: Thomas B <9094255+Ten0@users.noreply.github.com> Date: Fri, 12 Jul 2024 11:14:29 +0200 Subject: [PATCH] Don't generate a random to choose whether we should sample if sampling is fully disabled (rate = 0.0) (#667) --- sentry-core/src/client.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sentry-core/src/client.rs b/sentry-core/src/client.rs index 89fa0677..56bd0d22 100644 --- a/sentry-core/src/client.rs +++ b/sentry-core/src/client.rs @@ -2,8 +2,7 @@ use std::any::TypeId; use std::borrow::Cow; use std::fmt; use std::panic::RefUnwindSafe; -use std::sync::Arc; -use std::sync::RwLock; +use std::sync::{Arc, RwLock}; use std::time::Duration; use rand::random; @@ -377,6 +376,8 @@ impl Client { pub fn sample_should_send(&self, rate: f32) -> bool { if rate >= 1.0 { true + } else if rate <= 0.0 { + false } else { random::() < rate }