go - 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 中看不到它。
解决方案
使用sentry-go
SDK,在 Scope 上设置 Level。
文档:
- https://pkg.go.dev/github.com/getsentry/sentry-go?tab=doc#Scope.SetLevel
- https://pkg.go.dev/github.com/getsentry/sentry-go?tab=doc#Level
例子:
sentry.WithScope(func(scope *sentry.Scope) {
scope.SetLevel(sentry.LevelFatal)
sentry.CaptureException(errors.New("example error"))
})
推荐阅读
- autocomplete - Sublime Text 自定义自动完成层次结构
- html - 无法居中旋转 svg 元素
- javascript - 例外:无法发送电子邮件:没有收件人
- dataframe - 用 Julia Dataframe 中另一列的值替换缺失值
- c - MacOS Valgrind 的替代品?
- amazon-web-services - 将数据管道日志发送到 CloudWatch
- html - 尝试将 HTML 转换为属性字符串,但遇到运行时崩溃或长期警告
- algorithm - 不相交集算法中按大小联合与按等级联合
- laravel - formatLocalized 总是以英文给出结果
- csv - 如何在 D3.js 中绘制数据以从 csv 文件映射