Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SentrySDK.flush() #1013

Closed
philipphofmann opened this issue Mar 22, 2021 · 9 comments · Fixed by #2140
Closed

Add SentrySDK.flush() #1013

philipphofmann opened this issue Mar 22, 2021 · 9 comments · Fixed by #2140

Comments

@philipphofmann
Copy link
Member

philipphofmann commented Mar 22, 2021

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.

@bruno-garcia
Copy link
Member

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.

@martindufort
Copy link

+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

@philipphofmann
Copy link
Member Author

Hey, @martindufort. We don't have plans to add flush soon. What you described should be solved with #316. So ideally, our SDK would handle everything, and you don't need to call flush manually.

@martindufort
Copy link

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

@philipphofmann
Copy link
Member Author

Thanks for the update, @martindufort.

@mokagio
Copy link

mokagio commented Sep 12, 2022

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!

philipphofmann added a commit that referenced this issue Sep 12, 2022
Add blocking flush to send out all envelope items.

Fixes GH-1013
@philipphofmann philipphofmann mentioned this issue Sep 12, 2022
5 tasks
@philipphofmann
Copy link
Member Author

@mokagio, yes, the call will be blocking with a timeout parameter. Similar to DispatchGroup.wait(timeout:).

@mokagio
Copy link

mokagio commented Sep 13, 2022

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?

@philipphofmann
Copy link
Member Author

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
}

philipphofmann added a commit that referenced this issue Sep 19, 2022
Add blocking flush to send out all envelope items.

Fixes GH-1013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants