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 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64