Skip to content

Commit

Permalink
Make 0 sample rate a valid rate (#2573)
Browse files Browse the repository at this point in the history
  • Loading branch information
romtsn committed Feb 27, 2023
1 parent 079a025 commit d691d8f
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
### Fixes

- 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))
- Allow `0.0` error sample rate ([#2573](https://github.com/getsentry/sentry-java/pull/2573))

## 6.14.0

Expand Down
1 change: 0 additions & 1 deletion sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -3793,7 +3793,6 @@ public final class io/sentry/util/SampleRateUtils {
public fun <init> ()V
public static fun isValidProfilesSampleRate (Ljava/lang/Double;)Z
public static fun isValidSampleRate (Ljava/lang/Double;)Z
public static fun isValidSampleRate (Ljava/lang/Double;Z)Z
public static fun isValidTracesSampleRate (Ljava/lang/Double;)Z
public static fun isValidTracesSampleRate (Ljava/lang/Double;Z)Z
}
Expand Down
4 changes: 2 additions & 2 deletions sentry/src/main/java/io/sentry/SentryOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ public void setProxy(@Nullable Proxy proxy) {
}

/**
* Sets the sampleRate Can be anything between 0.01 and 1.0 or null (default), to disable it.
* Sets the sampleRate Can be anything between 0.0 and 1.0 or null (default), to disable it.
*
* @param sampleRate the sample rate
*/
Expand All @@ -823,7 +823,7 @@ public void setSampleRate(Double sampleRate) {
throw new IllegalArgumentException(
"The value "
+ sampleRate
+ " is not valid. Use null to disable or values > 0.0 and <= 1.0.");
+ " is not valid. Use null to disable or values >= 0.0 and <= 1.0.");
}
this.sampleRate = sampleRate;
}
Expand Down
10 changes: 1 addition & 9 deletions sentry/src/main/java/io/sentry/util/SampleRateUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@
public final class SampleRateUtils {

public static boolean isValidSampleRate(@Nullable Double sampleRate) {
return isValidSampleRate(sampleRate, true);
}

public static boolean isValidSampleRate(@Nullable Double sampleRate, boolean allowNull) {
if (sampleRate == null) {
return allowNull;
}

return !(sampleRate.isNaN() || sampleRate > 1.0 || sampleRate <= 0.0);
return isValidRate(sampleRate, true);
}

public static boolean isValidTracesSampleRate(@Nullable Double tracesSampleRate) {
Expand Down
5 changes: 0 additions & 5 deletions sentry/src/test/java/io/sentry/SentryOptionsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ class SentryOptionsTest {
assertFailsWith<IllegalArgumentException> { SentryOptions().sampleRate = -0.0000000000001 }
}

@Test
fun `when setSampling is set to exactly 0, setter throws`() {
assertFailsWith<IllegalArgumentException> { SentryOptions().sampleRate = 0.0 }
}

@Test
fun `when setTracesSampleRate is set to exactly 0, value is set`() {
val options = SentryOptions().apply {
Expand Down
14 changes: 2 additions & 12 deletions sentry/src/test/java/io/sentry/util/SampleRateUtilTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class SampleRateUtilTest {
}

@Test
fun `rejects 0 for sample rate`() {
assertFalse(SampleRateUtils.isValidSampleRate(0.0))
fun `accepts 0 for sample rate`() {
assertTrue(SampleRateUtils.isValidSampleRate(0.0))
}

@Test
Expand Down Expand Up @@ -46,16 +46,6 @@ class SampleRateUtilTest {
assertFalse(SampleRateUtils.isValidSampleRate(Double.NEGATIVE_INFINITY))
}

@Test
fun `accepts null sample rate if told so`() {
assertTrue(SampleRateUtils.isValidSampleRate(null, true))
}

@Test
fun `rejects null sample rate if told so`() {
assertFalse(SampleRateUtils.isValidSampleRate(null, false))
}

@Test
fun `accepts 0 for traces sample rate`() {
assertTrue(SampleRateUtils.isValidTracesSampleRate(0.0))
Expand Down

0 comments on commit d691d8f

Please sign in to comment.