首页 > 解决方案 > Sentry Go 集成,如何指定错误级别?

问题描述

根据官方文档https://docs.sentry.io/clients/go/,您可以从 golang 项目中记录 Sentry 中的错误:

// For Errors
raven.CapturePanic(func() {
    // do all of the scary things here
}, nil)

// For panic
if err != nil {
   raven.CaptureErrorAndWait(err, nil)
   log.Panic(err)
}

这就像一个魅力,问题在于 Sentry 中的两个函数都以“错误”级别记录。任何人都知道如何为每个呼叫指定日志记录级别?在 Python 中是非常明确的,但我在 Go 中看不到它。

标签: gosentry

解决方案


使用sentry-goSDK,在 Scope 上设置 Level。

文档:

例子:

    sentry.WithScope(func(scope *sentry.Scope) {
        scope.SetLevel(sentry.LevelFatal)
        sentry.CaptureException(errors.New("example error"))
    })

推荐阅读