douyun3022 2018-08-08 17:49
浏览 208

Sentry Go Integration,如何指定错误级别?

According to the official docs https://docs.sentry.io/clients/go/ you can log errors in Sentry from a golang project with:

// 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)
}

This works like a charm, the problem is in Sentry both functions are logged with level 'Error'. Anyone knows how can the logging level be specified for each call? In Python is very explicit, but I don't see it for Go.

  • 写回答

1条回答 默认 最新

  • dongzhang0418 2019-01-14 16:46
    关注

    I followed the advice in the comments, and came up with this:

    // sentryErrorCapture sends error data to Sentry asynchronously. Use for non-Fatal errors.
    var sentryErrorCapture = func(err error, severity raven.Severity, tags map[string]string, interfaces ...raven.Interface) string {
        packet := newSentryPackage(err, severity, tags, interfaces...)
        eventID, _ := raven.Capture(packet, tags)
        return eventID
    }
    
    
    func newSentryPackage(err error, severity raven.Severity, tags map[string]string, interfaces ...raven.Interface) (packet *raven.Packet) {
        interfaces = append(interfaces,
            raven.NewException(err, raven.GetOrNewStacktrace(err, 1, 3, raven.IncludePaths())))
    
        packet = &raven.Packet{
            Message:    err.Error(),
            Level:      severity,
            Interfaces: interfaces,
            Extra:      getSentryExtraInfo(),
        }
        return
    }
    

    When I want to log an error specifying the level I call: sentryErrorCapture(err, raven.ERROR, nil).

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭