sentry-java icon indicating copy to clipboard operation
sentry-java copied to clipboard

Send cached and pending envelopes when an envelope is going to be sent

Open marandaneto opened this issue 3 years ago • 4 comments

Related to https://github.com/getsentry/sentry-java/issues/912#issuecomment-1057079937

iOS already does it.

The use case is, you capture envelope A and you have no connection, the envelope is cached and won't be sent until you restart your app. If you didn't restart your app but you captured B another envelope, before sending envelope B, it's gonna read from the disk all cached and pending envelopes (read envelope A here) and send them in bulk.

marandaneto avatar Mar 03 '22 07:03 marandaneto

@philipphofmann Could you link the iOS implementation? thanks.

marandaneto avatar Mar 03 '22 07:03 marandaneto

iOS implementation: https://github.com/getsentry/sentry-cocoa/blob/ecedf79e89fc4e7ce900f3df60ad57b0178bb5df/Sources/Sentry/SentryHttpTransport.m#L137-L192

Here is a quick explanation of the approach so you don't have to read all the ObjC code:

  1. The following is true for any type of envelope
  2. The Client passes an envelope to HttpTransport
  3. HttpTransport stores the envelope to disk
  4. Storing the envelope potentially deletes envelopes and moves the session init if the storage limit is reached
  5. Try to send all envelopes starting with the oldest envelope

With https://github.com/getsentry/sentry-cocoa/pull/2263 the Cocoa SDK does 5. when the device gets back online.

philipphofmann avatar Mar 04 '22 11:03 philipphofmann

Looks like we should consider this https://github.com/getsentry/sentry-java/issues/1926 in order not to cause 429s.

adinauer avatar May 04 '22 09:05 adinauer

This is exactly what I'm missing from the disk cache feature. Now my app needs to be restarted, before the cached envelopes are being sent. I'd rather see this when it detects it has connection with the server again.

tomdevroomen avatar Jan 12 '23 14:01 tomdevroomen