sentry-java
sentry-java copied to clipboard
Send cached and pending envelopes when an envelope is going to be sent
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.
@philipphofmann Could you link the iOS implementation? thanks.
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:
- The following is true for any type of envelope
- The Client passes an envelope to HttpTransport
- HttpTransport stores the envelope to disk
- Storing the envelope potentially deletes envelopes and moves the session init if the storage limit is reached
- 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.
Looks like we should consider this https://github.com/getsentry/sentry-java/issues/1926 in order not to cause 429s.
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.