Skip to content
Permalink
Browse files

Better Sentry support

  • Loading branch information...
DarthSim committed Aug 19, 2019
1 parent b104c5c commit 12b59c379698b21b14f04eb0f9cc1b5b286b1540
Showing with 24 additions and 8 deletions.
  1. +2 −1 CHANGELOG.md
  2. +15 −6 errors_reporting.go
  3. +1 −1 go.mod
  4. +6 −0 go.sum
@@ -8,7 +8,8 @@
- Log to STDOUT;
- [filename](./docs/generating_the_url_advanced.md#filename) option;
- Only unexpected errors are reported to Bugsnag/Honeybadger/Sentry;
- GZip compression support is deprecated.
- GZip compression support is deprecated;
- Better Sentry support.

## v2.3.0

@@ -3,9 +3,10 @@ package main
import (
"net/http"
"strings"
"time"

"github.com/bugsnag/bugsnag-go"
"github.com/getsentry/raven-go"
"github.com/getsentry/sentry-go"
"github.com/honeybadger-io/honeybadger-go"
)

@@ -15,6 +16,7 @@ var (
sentryEnabled bool

headersReplacer = strings.NewReplacer("-", "_")
sentryTimeout = 5 * time.Second
)

func initErrorsReporting() {
@@ -35,9 +37,11 @@ func initErrorsReporting() {
}

if len(conf.SentryDSN) > 0 {
raven.SetDSN(conf.SentryDSN)
raven.SetEnvironment(conf.SentryEnvironment)
raven.SetRelease(conf.SentryRelease)
sentry.Init(sentry.ClientOptions{
Dsn: conf.SentryDSN,
Release: conf.SentryRelease,
Environment: conf.SentryEnvironment,
})

sentryEnabled = true
}
@@ -60,7 +64,12 @@ func reportError(err error, req *http.Request) {
}

if sentryEnabled {
raven.SetHttpContext(raven.NewHttp(req))
raven.CaptureError(err, nil)
hub := sentry.CurrentHub().Clone()
hub.Scope().SetRequest(sentry.Request{}.FromHTTPRequest(req))
hub.Scope().SetLevel(sentry.LevelError)
eventID := hub.CaptureException(err)
if eventID != nil {
hub.Flush(sentryTimeout)
}
}
}
2 go.mod
@@ -12,6 +12,7 @@ require (
github.com/bugsnag/panicwrap v1.2.0 // indirect
github.com/certifi/gocertifi v0.0.0-20180118203423-deb3ae2ef261 // indirect
github.com/getsentry/raven-go v0.2.0
github.com/getsentry/sentry-go v0.2.1
github.com/go-ole/go-ole v1.2.2 // indirect
github.com/gofrs/uuid v3.2.0+incompatible // indirect
github.com/google/martian v2.1.0+incompatible // indirect
@@ -24,7 +25,6 @@ require (
github.com/matoous/go-nanoid v0.0.0-20181114085210-eab626deece6
github.com/newrelic/go-agent v2.2.0+incompatible
github.com/pborman/uuid v0.0.0-20180906182336-adf5a7427709 // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/prometheus/client_golang v0.9.2
github.com/prometheus/client_model v0.0.0-20190109181635-f287a105a20e // indirect
github.com/prometheus/common v0.1.0 // indirect
6 go.sum
@@ -26,7 +26,11 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/getsentry/raven-go v0.2.0 h1:no+xWJRb5ZI7eE8TWgIq1jLulQiIoLG0IfYxv5JYMGs=
github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ=
github.com/getsentry/sentry-go v0.2.1 h1:zCyr8wS1NQM7ixbWNh8lBRMlQZSM3aMXQCqXgCDwI44=
github.com/getsentry/sentry-go v0.2.1/go.mod h1:2QfSdvxz4IZGyB5izm1TtADFhlhfj1Dcesrg8+A/T9Y=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w=
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-ole/go-ole v1.2.2 h1:QNWhweRd9D5Py2rRVboZ2L4SEoW/dyraWJCc8bgS8kE=
@@ -79,6 +83,8 @@ github.com/newrelic/go-agent v2.2.0+incompatible/go.mod h1:a8Fv1b/fYhFSReoTU6HDk
github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
github.com/pborman/uuid v0.0.0-20180906182336-adf5a7427709 h1:zNBQb37RGLmJybyMcs983HfUfpkw9OTFD9tbBfAViHE=
github.com/pborman/uuid v0.0.0-20180906182336-adf5a7427709/go.mod h1:VyrYX9gd7irzKovcSS6BIIEwPRkP2Wm2m9ufcdFSJ34=
github.com/pingcap/errors v0.11.1 h1:BXFZ6MdDd2U1uJUa2sRAWTmm+nieEzuyYM0R4aUTcC8=
github.com/pingcap/errors v0.11.1/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=

0 comments on commit 12b59c3

Please sign in to comment.
You can’t perform that action at this time.