没有刷新的哨兵 CaptureMessage

Sentry CaptureMessage without Flush

我说的对吧,在Go项目中要立即发送消息,必须使用Flush方法吗? 当我尝试在没有 Flush() 的情况下发送消息时,它根本不起作用。

来自docs

Flush waits until the underlying Transport sends any buffered events 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.

Flush should be called before terminating the program to avoid unintentionally dropping events.

Do not call Flush indiscriminately after every call to CaptureEvent, CaptureException or CaptureMessage. Instead, to have the SDK send events over the network synchronously, configure it to use the HTTPSyncTransport in the call to Init.

因此,虽然您询问的问题是一个“有效”问题,以防您需要确保消息确实已发送到服务器,但您提出的解决方案(在 Flush() CaptureMessage()),SDK 作者积极劝阻。相反,请考虑以下内容:

sentry.Init(sentry.ClientOptions{
    Transport: sentry.NewHTTPSyncTransport(),
    // ...
}) 

我会接受 Emile Pels 的回答并进行更正
sentry.NewHTTPSyncTransport() 应该分配
Transport 而不是 HTTPTransport