blob: a63207201191488ff0a23ee0bb7918700e7ed33e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
package sentry
import (
"fmt"
sentry "github.com/getsentry/sentry-go"
log "github.com/sirupsen/logrus"
"gitlab.com/gitlab-org/gitaly/v16/internal/grpc/middleware/panichandler"
)
// Config contains configuration for sentry
type Config struct {
DSN string `toml:"sentry_dsn,omitempty"`
Environment string `toml:"sentry_environment,omitempty"`
}
// ConfigureSentry configures the sentry DSN
func ConfigureSentry(version string, sentryConf Config) {
if sentryConf.DSN == "" {
return
}
err := sentry.Init(sentry.ClientOptions{
Dsn: sentryConf.DSN,
Environment: sentryConf.Environment,
Release: "v" + version,
})
if err != nil {
log.Warnf("Unable to initialize sentry client: %v", err)
return
}
log.Debug("Using sentry logging")
panichandler.InstallPanicHandler(func(grpcMethod string, _err interface{}) {
err, ok := _err.(error)
if !ok {
err = fmt.Errorf("%v", _err)
}
sentry.WithScope(func(scope *sentry.Scope) {
scope.SetTag("grpcMethod", grpcMethod)
scope.SetTag("panic", "1")
sentry.CaptureException(err)
})
})
}
|