Add SentrySDK.flush()
The unified API states that the SDK should offer flush to flush all queued events; see https://develop.sentry.dev/sdk/unified-api/#client. Checkout the implementation, for example, of .NET as a reference.
Please upvote if this is a feature you want.
The reason we didn't have flush so far is that crashes and capture methods persisted files to disk synchronously. Recently we moved this to a background thread not to cause any latency to the main thread so flush is needed now.
+1 for this. In some weird cases, our app would crash on launch without allowing time for the Sentry SDK to report the bug. When the user restarts, then same behavior would happen again thus accumulating crash logs locally.
Having a flush() method would allow us to flush the Sentry crash log store in an execution state that we know the app is stable before continuing with our app launch process.
Any timeline for the availability of this:
SentrySDK.flush(completionHandler:)
Thanks
Hey, @martindufort. We don't have plans to add flush soon. What you described should be solved with https://github.com/getsentry/sentry-cocoa/issues/316. So ideally, our SDK would handle everything, and you don't need to call flush manually.
Hey @philipphofmann,
You are totally right. After investigation on our side, we found the boot crash was occuring before the Sentry SDK was initialized. 😵💫.
We changed our initialization sequence tp ensure Sentry is initialized before the boot crash. Thanks for the reply - Martin
Thanks for the update, @martindufort.
Do you plan to make flush() synchronous? Or to add a completion handler?
I read somewhere that events are "send and forget" by design, which is understandable. I still think it would be nice to know once all events have ben sent via that method.
The particular use cases I can think of for having a completion acknowledgement mechanism of sort are:
- Let the user know about the completion, e.g. in a debug screen that has an option to force a flush
- Allow the app to update its state after events have been sent. E.g. 1) reach inconsistent state; 2) log even about it; 3) flush events to make sure Sentry receives them; 4) force a crash to recover from the inconsistent state
Thanks!
@mokagio, yes, the call will be blocking with a timeout parameter. Similar to DispatchGroup.wait(timeout:).
the call will be blocking with a timeout parameter
Thanks!
As a consumer, I would really love a completion handler. I'm guessing the choice of making it blocking with a timeout is to cope with the possibility of having a long stash of events to send and not being able to guarantee they'll all be sent in a reasonable time?
I'm guessing the choice of making it blocking with a timeout is to cope with the possibility of having a long stash of events to send and not being able to guarantee they'll all be sent in a reasonable time?
Yes, indeed.
We don't have a completion handler in any of our SDKs. It's not part of our unified API, see https://develop.sentry.dev/sdk/unified-api/#client. Still, you could build your own completion handler with something like
SentrySDK.capture(message: "Your message")
let queue = DispatchQueue(label: "YourQueue")
queue.async {
SentrySDK.flush(timeout: 1000000)
// call your completion handler
}