Skip to content

Commit 0d0c782

Browse files
committed
Do not report cached events as lost
1 parent 34f4b72 commit 0d0c782

6 files changed

Lines changed: 43 additions & 19 deletions

File tree

sentry-android-core/src/main/java/io/sentry/android/core/cache/AndroidEnvelopeCache.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public AndroidEnvelopeCache(final @NotNull SentryAndroidOptions options) {
4747
this.currentDateProvider = currentDateProvider;
4848
}
4949

50+
@SuppressWarnings("deprecation")
5051
@Override
5152
public void store(@NotNull SentryEnvelope envelope, @NotNull Hint hint) {
5253
super.store(envelope, hint);

sentry/api/sentry.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4357,6 +4357,7 @@ public abstract interface class io/sentry/cache/IEnvelopeCache : java/lang/Itera
43574357
public abstract fun discard (Lio/sentry/SentryEnvelope;)V
43584358
public fun store (Lio/sentry/SentryEnvelope;)V
43594359
public abstract fun store (Lio/sentry/SentryEnvelope;Lio/sentry/Hint;)V
4360+
public fun storeEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/Hint;)Z
43604361
}
43614362

43624363
public final class io/sentry/cache/PersistingOptionsObserver : io/sentry/IOptionsObserver {
@@ -6659,6 +6660,7 @@ public final class io/sentry/transport/NoOpEnvelopeCache : io/sentry/cache/IEnve
66596660
public static fun getInstance ()Lio/sentry/transport/NoOpEnvelopeCache;
66606661
public fun iterator ()Ljava/util/Iterator;
66616662
public fun store (Lio/sentry/SentryEnvelope;Lio/sentry/Hint;)V
6663+
public fun storeEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/Hint;)Z
66626664
}
66636665

66646666
public final class io/sentry/transport/NoOpTransport : io/sentry/transport/ITransport {

sentry/src/main/java/io/sentry/cache/EnvelopeCache.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public EnvelopeCache(
9393
previousSessionLatch = new CountDownLatch(1);
9494
}
9595

96+
@SuppressWarnings("deprecation")
9697
@Override
9798
public void store(final @NotNull SentryEnvelope envelope, final @NotNull Hint hint) {
9899
Objects.requireNonNull(envelope, "Envelope is required.");

sentry/src/main/java/io/sentry/cache/IEnvelopeCache.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@
66

77
public interface IEnvelopeCache extends Iterable<SentryEnvelope> {
88

9+
@Deprecated
910
void store(@NotNull SentryEnvelope envelope, @NotNull Hint hint);
1011

12+
default boolean storeEnvelope(@NotNull SentryEnvelope envelope, @NotNull Hint hint) {
13+
store(envelope, hint);
14+
return true;
15+
}
16+
17+
@Deprecated
1118
default void store(@NotNull SentryEnvelope envelope) {
12-
store(envelope, new Hint());
19+
storeEnvelope(envelope, new Hint());
1320
}
1421

1522
void discard(@NotNull SentryEnvelope envelope);

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

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private static QueuedThreadPoolExecutor initExecutor(
139139
final EnvelopeSender envelopeSender = (EnvelopeSender) r;
140140

141141
if (!HintUtils.hasType(envelopeSender.hint, Cached.class)) {
142-
envelopeCache.store(envelopeSender.envelope, envelopeSender.hint);
142+
envelopeCache.storeEnvelope(envelopeSender.envelope, envelopeSender.hint);
143143
}
144144

145145
markHintWhenSendingFailed(envelopeSender.hint, true);
@@ -268,7 +268,7 @@ public void run() {
268268
TransportResult result = this.failedResult;
269269

270270
envelope.getHeader().setSentAt(null);
271-
envelopeCache.store(envelope, hint);
271+
boolean cached = envelopeCache.storeEnvelope(envelope, hint);
272272

273273
HintUtils.runIfHasType(
274274
hint,
@@ -308,14 +308,17 @@ public void run() {
308308

309309
// ignore e.g. 429 as we're not the ones actively dropping
310310
if (result.getResponseCode() >= 400 && result.getResponseCode() != 429) {
311-
HintUtils.runIfDoesNotHaveType(
312-
hint,
313-
Retryable.class,
314-
(hint) -> {
315-
options
316-
.getClientReportRecorder()
317-
.recordLostEnvelope(DiscardReason.NETWORK_ERROR, envelopeWithClientReport);
318-
});
311+
if (!cached) {
312+
HintUtils.runIfDoesNotHaveType(
313+
hint,
314+
Retryable.class,
315+
(hint) -> {
316+
options
317+
.getClientReportRecorder()
318+
.recordLostEnvelope(
319+
DiscardReason.NETWORK_ERROR, envelopeWithClientReport);
320+
});
321+
}
319322
}
320323

321324
throw new IllegalStateException(message);
@@ -329,10 +332,12 @@ public void run() {
329332
retryable.setRetry(true);
330333
},
331334
(hint, clazz) -> {
332-
LogUtils.logNotInstanceOf(clazz, hint, options.getLogger());
333-
options
334-
.getClientReportRecorder()
335-
.recordLostEnvelope(DiscardReason.NETWORK_ERROR, envelopeWithClientReport);
335+
if (!cached) {
336+
LogUtils.logNotInstanceOf(clazz, hint, options.getLogger());
337+
options
338+
.getClientReportRecorder()
339+
.recordLostEnvelope(DiscardReason.NETWORK_ERROR, envelopeWithClientReport);
340+
}
336341
});
337342
throw new IllegalStateException("Sending the event failed.", e);
338343
}
@@ -345,10 +350,12 @@ public void run() {
345350
retryable.setRetry(true);
346351
},
347352
(hint, clazz) -> {
348-
LogUtils.logNotInstanceOf(clazz, hint, options.getLogger());
349-
options
350-
.getClientReportRecorder()
351-
.recordLostEnvelope(DiscardReason.NETWORK_ERROR, envelope);
353+
if (!cached) {
354+
LogUtils.logNotInstanceOf(clazz, hint, options.getLogger());
355+
options
356+
.getClientReportRecorder()
357+
.recordLostEnvelope(DiscardReason.NETWORK_ERROR, envelope);
358+
}
352359
});
353360
}
354361
return result;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@ public static NoOpEnvelopeCache getInstance() {
1414
return instance;
1515
}
1616

17+
@SuppressWarnings("deprecation")
1718
@Override
1819
public void store(@NotNull SentryEnvelope envelope, @NotNull Hint hint) {}
1920

21+
@Override
22+
public boolean storeEnvelope(@NotNull SentryEnvelope envelope, @NotNull Hint hint) {
23+
return false;
24+
}
25+
2026
@Override
2127
public void discard(@NotNull SentryEnvelope envelope) {}
2228

0 commit comments

Comments
 (0)