Skip to content

Commit 159a367

Browse files
authored
Mark hint flushed when rate limited (#3892)
* mark hint flushed on rate limit * always mark flushed if rate limited * changelog * cleanup test
1 parent dc2af27 commit 159a367

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
### Fixes
1111

12+
- Mark `DiskFlushNotification` hint flushed when rate limited ([#3892](https://github.com/getsentry/sentry-java/pull/3892))
13+
- Our `UncaughtExceptionHandlerIntegration` waited for the full flush timeout duration (default 15s) when rate limited.
1214
- Do not replace `op` with auto generated content for OpenTelemetry spans with span kind `INTERNAL` ([#3906](https://github.com/getsentry/sentry-java/pull/3906))
1315

1416
## 8.0.0-beta.2

sentry/src/main/java/io/sentry/transport/RateLimiter.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.sentry.SentryLevel;
1111
import io.sentry.SentryOptions;
1212
import io.sentry.clientreport.DiscardReason;
13+
import io.sentry.hints.DiskFlushNotification;
1314
import io.sentry.hints.Retryable;
1415
import io.sentry.hints.SubmissionResult;
1516
import io.sentry.util.HintUtils;
@@ -135,9 +136,16 @@ public boolean isAnyRateLimitActive() {
135136
* @param hint the Hints
136137
* @param retry if event should be retried or not
137138
*/
138-
private static void markHintWhenSendingFailed(final @NotNull Hint hint, final boolean retry) {
139+
private void markHintWhenSendingFailed(final @NotNull Hint hint, final boolean retry) {
139140
HintUtils.runIfHasType(hint, SubmissionResult.class, result -> result.setResult(false));
140141
HintUtils.runIfHasType(hint, Retryable.class, retryable -> retryable.setRetry(retry));
142+
HintUtils.runIfHasType(
143+
hint,
144+
DiskFlushNotification.class,
145+
(diskFlushNotification) -> {
146+
diskFlushNotification.markFlushed();
147+
options.getLogger().log(SentryLevel.DEBUG, "Disk flush envelope fired due to rate limit");
148+
});
141149
}
142150

143151
/**

sentry/src/test/java/io/sentry/transport/RateLimiterTest.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ import io.sentry.TransactionContext
2020
import io.sentry.UserFeedback
2121
import io.sentry.clientreport.DiscardReason
2222
import io.sentry.clientreport.IClientReportRecorder
23+
import io.sentry.hints.DiskFlushNotification
2324
import io.sentry.protocol.SentryId
2425
import io.sentry.protocol.SentryTransaction
2526
import io.sentry.protocol.User
27+
import io.sentry.util.HintUtils
2628
import org.mockito.kotlin.eq
2729
import org.mockito.kotlin.mock
2830
import org.mockito.kotlin.same
@@ -285,4 +287,20 @@ class RateLimiterTest {
285287

286288
assertTrue(rateLimiter.isAnyRateLimitActive)
287289
}
290+
291+
@Test
292+
fun `on rate limit DiskFlushNotification is marked as flushed`() {
293+
val rateLimiter = fixture.getSUT()
294+
whenever(fixture.currentDateProvider.currentTimeMillis).thenReturn(0)
295+
val sentryEvent = SentryEvent()
296+
val eventItem = SentryEnvelopeItem.fromEvent(fixture.serializer, sentryEvent)
297+
val envelope = SentryEnvelope(SentryEnvelopeHeader(sentryEvent.eventId), arrayListOf(eventItem))
298+
299+
rateLimiter.updateRetryAfterLimits("50:transaction:key, 1:default;error;security:organization", null, 1)
300+
301+
val hint = mock<DiskFlushNotification>()
302+
rateLimiter.filter(envelope, HintUtils.createWithTypeCheckHint(hint))
303+
304+
verify(hint).markFlushed()
305+
}
288306
}

0 commit comments

Comments
 (0)