Skip to content

Commit d691d8f

Browse files
authored
Make 0 sample rate a valid rate (#2573)
1 parent 079a025 commit d691d8f

File tree

6 files changed

+6
-29
lines changed

6 files changed

+6
-29
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
### Fixes
1616

1717
- Leave `inApp` flag for stack frames undecided in SDK if unsure and let ingestion decide instead ([#2547](https://github.com/getsentry/sentry-java/pull/2547))
18+
- Allow `0.0` error sample rate ([#2573](https://github.com/getsentry/sentry-java/pull/2573))
1819

1920
## 6.14.0
2021

sentry/api/sentry.api

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3793,7 +3793,6 @@ public final class io/sentry/util/SampleRateUtils {
37933793
public fun <init> ()V
37943794
public static fun isValidProfilesSampleRate (Ljava/lang/Double;)Z
37953795
public static fun isValidSampleRate (Ljava/lang/Double;)Z
3796-
public static fun isValidSampleRate (Ljava/lang/Double;Z)Z
37973796
public static fun isValidTracesSampleRate (Ljava/lang/Double;)Z
37983797
public static fun isValidTracesSampleRate (Ljava/lang/Double;Z)Z
37993798
}

sentry/src/main/java/io/sentry/SentryOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ public void setProxy(@Nullable Proxy proxy) {
814814
}
815815

816816
/**
817-
* Sets the sampleRate Can be anything between 0.01 and 1.0 or null (default), to disable it.
817+
* Sets the sampleRate Can be anything between 0.0 and 1.0 or null (default), to disable it.
818818
*
819819
* @param sampleRate the sample rate
820820
*/
@@ -823,7 +823,7 @@ public void setSampleRate(Double sampleRate) {
823823
throw new IllegalArgumentException(
824824
"The value "
825825
+ sampleRate
826-
+ " is not valid. Use null to disable or values > 0.0 and <= 1.0.");
826+
+ " is not valid. Use null to disable or values >= 0.0 and <= 1.0.");
827827
}
828828
this.sampleRate = sampleRate;
829829
}

sentry/src/main/java/io/sentry/util/SampleRateUtils.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,7 @@
77
public final class SampleRateUtils {
88

99
public static boolean isValidSampleRate(@Nullable Double sampleRate) {
10-
return isValidSampleRate(sampleRate, true);
11-
}
12-
13-
public static boolean isValidSampleRate(@Nullable Double sampleRate, boolean allowNull) {
14-
if (sampleRate == null) {
15-
return allowNull;
16-
}
17-
18-
return !(sampleRate.isNaN() || sampleRate > 1.0 || sampleRate <= 0.0);
10+
return isValidRate(sampleRate, true);
1911
}
2012

2113
public static boolean isValidTracesSampleRate(@Nullable Double tracesSampleRate) {

sentry/src/test/java/io/sentry/SentryOptionsTest.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ class SentryOptionsTest {
9191
assertFailsWith<IllegalArgumentException> { SentryOptions().sampleRate = -0.0000000000001 }
9292
}
9393

94-
@Test
95-
fun `when setSampling is set to exactly 0, setter throws`() {
96-
assertFailsWith<IllegalArgumentException> { SentryOptions().sampleRate = 0.0 }
97-
}
98-
9994
@Test
10095
fun `when setTracesSampleRate is set to exactly 0, value is set`() {
10196
val options = SentryOptions().apply {

sentry/src/test/java/io/sentry/util/SampleRateUtilTest.kt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class SampleRateUtilTest {
1717
}
1818

1919
@Test
20-
fun `rejects 0 for sample rate`() {
21-
assertFalse(SampleRateUtils.isValidSampleRate(0.0))
20+
fun `accepts 0 for sample rate`() {
21+
assertTrue(SampleRateUtils.isValidSampleRate(0.0))
2222
}
2323

2424
@Test
@@ -46,16 +46,6 @@ class SampleRateUtilTest {
4646
assertFalse(SampleRateUtils.isValidSampleRate(Double.NEGATIVE_INFINITY))
4747
}
4848

49-
@Test
50-
fun `accepts null sample rate if told so`() {
51-
assertTrue(SampleRateUtils.isValidSampleRate(null, true))
52-
}
53-
54-
@Test
55-
fun `rejects null sample rate if told so`() {
56-
assertFalse(SampleRateUtils.isValidSampleRate(null, false))
57-
}
58-
5949
@Test
6050
fun `accepts 0 for traces sample rate`() {
6151
assertTrue(SampleRateUtils.isValidTracesSampleRate(0.0))

0 commit comments

Comments
 (0)