Skip to content

Commit d08633d

Browse files
authored
[Logs 9] Remove logs.sample-rate option (#4389)
* Add Log feature to Java SDK * Rate limit for log items * Add options for logs * Add batch processor for logs * Use a separate ExecutorService for log batching * Reduce locking when log event is created * Add system tests for Logs * Separate enum for SentryLogLevel * Remove logsSampleRate option
1 parent 1e23fdc commit d08633d

File tree

8 files changed

+2
-93
lines changed

8 files changed

+2
-93
lines changed

sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ class SentryAutoConfigurationTest {
188188
"sentry.cron.default-timezone=America/New_York",
189189
"sentry.cron.default-failure-issue-threshold=40",
190190
"sentry.cron.default-recovery-threshold=50",
191-
"sentry.experimental.logs.enabled=true",
192-
"sentry.experimental.logs.sample-rate=0.4"
191+
"sentry.experimental.logs.enabled=true"
193192
).run {
194193
val options = it.getBean(SentryProperties::class.java)
195194
assertThat(options.readTimeoutMillis).isEqualTo(10)
@@ -235,7 +234,6 @@ class SentryAutoConfigurationTest {
235234
assertThat(options.cron!!.defaultFailureIssueThreshold).isEqualTo(40L)
236235
assertThat(options.cron!!.defaultRecoveryThreshold).isEqualTo(50L)
237236
assertThat(options.experimental.logs.isEnabled).isEqualTo(true)
238-
assertThat(options.experimental.logs.sampleRate).isEqualTo(0.4)
239237
}
240238
}
241239

sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ class SentryAutoConfigurationTest {
187187
"sentry.cron.default-timezone=America/New_York",
188188
"sentry.cron.default-failure-issue-threshold=40",
189189
"sentry.cron.default-recovery-threshold=50",
190-
"sentry.experimental.logs.enabled=true",
191-
"sentry.experimental.logs.sample-rate=0.4"
190+
"sentry.experimental.logs.enabled=true"
192191
).run {
193192
val options = it.getBean(SentryProperties::class.java)
194193
assertThat(options.readTimeoutMillis).isEqualTo(10)
@@ -234,7 +233,6 @@ class SentryAutoConfigurationTest {
234233
assertThat(options.cron!!.defaultFailureIssueThreshold).isEqualTo(40L)
235234
assertThat(options.cron!!.defaultRecoveryThreshold).isEqualTo(50L)
236235
assertThat(options.experimental.logs.isEnabled).isEqualTo(true)
237-
assertThat(options.experimental.logs.sampleRate).isEqualTo(0.4)
238236
}
239237
}
240238

sentry/api/sentry.api

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,6 @@ public final class io/sentry/ExternalOptions {
493493
public fun getIgnoredTransactions ()Ljava/util/List;
494494
public fun getInAppExcludes ()Ljava/util/List;
495495
public fun getInAppIncludes ()Ljava/util/List;
496-
public fun getLogsSampleRate ()Ljava/lang/Double;
497496
public fun getMaxRequestBodySize ()Lio/sentry/SentryOptions$RequestSize;
498497
public fun getPrintUncaughtStackTrace ()Ljava/lang/Boolean;
499498
public fun getProfilesSampleRate ()Ljava/lang/Double;
@@ -535,7 +534,6 @@ public final class io/sentry/ExternalOptions {
535534
public fun setIgnoredCheckIns (Ljava/util/List;)V
536535
public fun setIgnoredErrors (Ljava/util/List;)V
537536
public fun setIgnoredTransactions (Ljava/util/List;)V
538-
public fun setLogsSampleRate (Ljava/lang/Double;)V
539537
public fun setMaxRequestBodySize (Lio/sentry/SentryOptions$RequestSize;)V
540538
public fun setPrintUncaughtStackTrace (Ljava/lang/Boolean;)V
541539
public fun setProfilesSampleRate (Ljava/lang/Double;)V
@@ -3457,11 +3455,9 @@ public final class io/sentry/SentryOptions$Cron {
34573455
public final class io/sentry/SentryOptions$Logs {
34583456
public fun <init> ()V
34593457
public fun getBeforeSend ()Lio/sentry/SentryOptions$Logs$BeforeSendLogCallback;
3460-
public fun getSampleRate ()Ljava/lang/Double;
34613458
public fun isEnabled ()Z
34623459
public fun setBeforeSend (Lio/sentry/SentryOptions$Logs$BeforeSendLogCallback;)V
34633460
public fun setEnabled (Z)V
3464-
public fun setSampleRate (Ljava/lang/Double;)V
34653461
}
34663462

34673463
public abstract interface class io/sentry/SentryOptions$Logs$BeforeSendLogCallback {

sentry/src/main/java/io/sentry/ExternalOptions.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public final class ExternalOptions {
2525
private @Nullable Boolean enableDeduplication;
2626
private @Nullable Double tracesSampleRate;
2727
private @Nullable Double profilesSampleRate;
28-
private @Nullable Double logsSampleRate;
2928
private @Nullable SentryOptions.RequestSize maxRequestBodySize;
3029
private final @NotNull Map<String, @NotNull String> tags = new ConcurrentHashMap<>();
3130
private @Nullable SentryOptions.Proxy proxy;
@@ -153,8 +152,6 @@ public final class ExternalOptions {
153152
propertiesProvider.getBooleanProperty("capture-open-telemetry-events"));
154153

155154
options.setEnableLogs(propertiesProvider.getBooleanProperty("experimental.logs.enabled"));
156-
options.setLogsSampleRate(
157-
propertiesProvider.getDoubleProperty("experimental.logs.sample-rate"));
158155

159156
for (final String ignoredExceptionType :
160157
propertiesProvider.getList("ignored-exceptions-for-type")) {
@@ -534,14 +531,4 @@ public void setEnableLogs(final @Nullable Boolean enableLogs) {
534531
public @Nullable Boolean isEnableLogs() {
535532
return enableLogs;
536533
}
537-
538-
@ApiStatus.Experimental
539-
public @Nullable Double getLogsSampleRate() {
540-
return logsSampleRate;
541-
}
542-
543-
@ApiStatus.Experimental
544-
public void setLogsSampleRate(final @Nullable Double logsSampleRate) {
545-
this.logsSampleRate = logsSampleRate;
546-
}
547534
}

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

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3205,10 +3205,6 @@ public void merge(final @NotNull ExternalOptions options) {
32053205
if (options.isEnableLogs() != null) {
32063206
getExperimental().getLogs().setEnabled(options.isEnableLogs());
32073207
}
3208-
3209-
if (options.getLogsSampleRate() != null) {
3210-
getExperimental().getLogs().setSampleRate(options.getLogsSampleRate());
3211-
}
32123208
}
32133209

32143210
private @NotNull SdkVersion createSdkVersion() {
@@ -3369,13 +3365,6 @@ public static final class Logs {
33693365
/** Whether Sentry Logs feature is enabled and Sentry.logger() usages are sent to Sentry. */
33703366
@ApiStatus.Experimental private boolean enable = false;
33713367

3372-
/**
3373-
* Configures the sample rate as a percentage of log items to be sent in the range of 0.0 to
3374-
* 1.0. if 1.0 is set it means that 100% of items are sent. If set to 0.1 only 10% of items will
3375-
* be sent. Items are picked randomly. Default is 1.0
3376-
*/
3377-
@ApiStatus.Experimental private @Nullable Double sampleRate = 1.0;
3378-
33793368
/**
33803369
* This function is called with an SDK specific log event object and can return a modified event
33813370
* object or nothing to skip reporting the log item
@@ -3422,32 +3411,6 @@ public void setBeforeSend(@Nullable BeforeSendLogCallback beforeSendLog) {
34223411
this.beforeSend = beforeSendLog;
34233412
}
34243413

3425-
/**
3426-
* Returns the logs sample rate Default is null (disabled)
3427-
*
3428-
* @return the logs sample rate
3429-
*/
3430-
@ApiStatus.Experimental
3431-
public @Nullable Double getSampleRate() {
3432-
return sampleRate;
3433-
}
3434-
3435-
/**
3436-
* Sets the logsSampleRate Can be anything between 0.0 and 1.0 (default) or null to disable it.
3437-
*
3438-
* @param logsSampleRate the sample rate for log events
3439-
*/
3440-
@ApiStatus.Experimental
3441-
public void setSampleRate(Double logsSampleRate) {
3442-
if (!SampleRateUtils.isValidSampleRate(logsSampleRate)) {
3443-
throw new IllegalArgumentException(
3444-
"The value "
3445-
+ logsSampleRate
3446-
+ " is not valid. Use null to disable or values >= 0.0 and <= 1.0.");
3447-
}
3448-
this.sampleRate = logsSampleRate;
3449-
}
3450-
34513414
/** The BeforeSendLog callback */
34523415
public interface BeforeSendLogCallback {
34533416

sentry/src/main/java/io/sentry/logger/LoggerApi.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.sentry.logger;
22

3-
import io.sentry.DataCategory;
43
import io.sentry.Hint;
54
import io.sentry.ISpan;
65
import io.sentry.PropagationContext;
@@ -12,11 +11,8 @@
1211
import io.sentry.SentryLogLevel;
1312
import io.sentry.SentryOptions;
1413
import io.sentry.SpanId;
15-
import io.sentry.clientreport.DiscardReason;
1614
import io.sentry.protocol.SdkVersion;
1715
import io.sentry.protocol.SentryId;
18-
import io.sentry.util.Random;
19-
import io.sentry.util.SentryRandom;
2016
import java.util.HashMap;
2117
import org.jetbrains.annotations.ApiStatus;
2218
import org.jetbrains.annotations.NotNull;
@@ -107,16 +103,6 @@ private void captureLog(
107103
return;
108104
}
109105

110-
if (!sampleLog(options)) {
111-
options
112-
.getLogger()
113-
.log(SentryLevel.DEBUG, "Log Event was dropped due to sampling decision.");
114-
options
115-
.getClientReportRecorder()
116-
.recordLostEvent(DiscardReason.SAMPLE_RATE, DataCategory.LogItem);
117-
return;
118-
}
119-
120106
final @NotNull SentryDate timestampToUse =
121107
timestamp == null ? options.getDateProvider().now() : timestamp;
122108
final @NotNull String messageToUse = args == null ? message : String.format(message, args);
@@ -137,16 +123,6 @@ private void captureLog(
137123
}
138124
}
139125

140-
private boolean sampleLog(final @NotNull SentryOptions options) {
141-
final @Nullable Random random =
142-
options.getExperimental().getLogs().getSampleRate() == null ? null : SentryRandom.current();
143-
if (options.getExperimental().getLogs().getSampleRate() != null && random != null) {
144-
final double sampling = options.getExperimental().getLogs().getSampleRate();
145-
return !(sampling < random.nextDouble()); // bad luck
146-
}
147-
return false;
148-
}
149-
150126
private @NotNull HashMap<String, SentryLogEventAttributeValue> createAttributes(
151127
final @NotNull String message, final @NotNull SpanId spanId, final @Nullable Object... args) {
152128
final @NotNull HashMap<String, SentryLogEventAttributeValue> attributes = new HashMap<>();

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,6 @@ class ExternalOptionsTest {
382382
}
383383
}
384384

385-
@Test
386-
fun `creates options with logsSampleRate using external properties`() {
387-
withPropertiesFile("experimental.logs.sample-rate=0.2") {
388-
assertEquals(0.2, it.logsSampleRate)
389-
}
390-
}
391-
392385
private fun withPropertiesFile(textLines: List<String> = emptyList(), logger: ILogger = mock(), fn: (ExternalOptions) -> Unit) {
393386
// create a sentry.properties file in temporary folder
394387
val temporaryFolder = TemporaryFolder()

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,6 @@ class SentryOptionsTest {
415415
externalOptions.spotlightConnectionUrl = "http://local.sentry.io:1234"
416416
externalOptions.isGlobalHubMode = true
417417
externalOptions.isEnableLogs = true
418-
externalOptions.logsSampleRate = 0.6
419418

420419
val options = SentryOptions()
421420

@@ -461,7 +460,6 @@ class SentryOptionsTest {
461460
assertEquals("http://local.sentry.io:1234", options.spotlightConnectionUrl)
462461
assertTrue(options.isGlobalHubMode!!)
463462
assertTrue(options.experimental.logs.isEnabled!!)
464-
assertEquals(0.6, options.experimental.logs.sampleRate)
465463
}
466464

467465
@Test

0 commit comments

Comments
 (0)