1818import io .sentry .util .HintUtils ;
1919import io .sentry .util .Objects ;
2020import io .sentry .util .Random ;
21+ import io .sentry .util .SentryRandom ;
2122import io .sentry .util .TracingUtils ;
2223import java .io .Closeable ;
2324import java .io .IOException ;
@@ -40,7 +41,6 @@ public final class SentryClient implements ISentryClient, IMetricsClient {
4041
4142 private final @ NotNull SentryOptions options ;
4243 private final @ NotNull ITransport transport ;
43- private final @ Nullable Random random ;
4444 private final @ NotNull SortBreadcrumbsByDate sortBreadcrumbsByDate = new SortBreadcrumbsByDate ();
4545 private final @ NotNull IMetricsAggregator metricsAggregator ;
4646
@@ -66,8 +66,6 @@ public boolean isEnabled() {
6666 options .isEnableMetrics ()
6767 ? new MetricsAggregator (options , this )
6868 : NoopMetricsAggregator .getInstance ();
69-
70- this .random = options .getSampleRate () == null ? null : new Random ();
7169 }
7270
7371 private boolean shouldApplyScopeData (
@@ -1183,6 +1181,7 @@ public boolean isHealthy() {
11831181 }
11841182
11851183 private boolean sample () {
1184+ final @ Nullable Random random = options .getSampleRate () == null ? null : SentryRandom .current ();
11861185 // https://docs.sentry.io/development/sdk-dev/features/#event-sampling
11871186 if (options .getSampleRate () != null && random != null ) {
11881187 final double sampling = options .getSampleRate ();
0 commit comments