获取更多动态,关注公众号:黑客下午茶

Shutdown and Draining

大多数 SDK 的默认行为是在后台通过网络异步发送事件。这意味着如果应用程序意外关闭,某些事件可能会丢失。SDK 提供了应对这种情况的机制。

To avoid unintentionally dropping events when the program terminates, arrange for sentry.Flush to be called, typically using defer.

If you use multiple clients, arrange for each of them to be flushed as appropriate.

Flush waits until any buffered events are sent to the Sentry server, blocking for at most the given timeout. It returns false if the timeout was reached. In that case, some events may not have been sent.

Copied
func main() {
	// err := sentry.Init(...)
	defer sentry.Flush(2 * time.Second)

	sentry.CaptureMessage("my message")
}
You can edit this page on GitHub.