-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
80 lines (68 loc) · 1.4 KB
/
config.go
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package apm
import (
"runtime/debug"
"sync"
"github.com/getsentry/sentry-go"
"github.com/rs/zerolog"
)
var (
hc Healthchecks
loglevel zerolog.Level
initialized bool
initMu sync.Mutex
sentryDSN string
sentryName string
sentryVersion = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return setting.Value
}
}
}
return "development"
}()
)
// SetName sets the name of the application
func SetName(name string) {
sentryName = name
}
// SetLogLevel sets the log level
func SetLogLevel(level string) {
var err error
loglevel, err = zerolog.ParseLevel(level)
if err != nil {
loglevel = zerolog.InfoLevel
}
zerolog.SetGlobalLevel(loglevel)
}
// SetSentryDSN sets the sentry DSN and initializes it
func SetSentryDSN(dsn string) {
sentryDSN = dsn
initSentry()
}
// SetHealthchecks sets the healthchecks client
func SetHealthchecks(h Healthchecks) {
hc = h
}
// initSentry initializes sentry
func initSentry() {
initMu.Lock()
defer initMu.Unlock()
if initialized {
return
}
if sentryDSN == "" {
return
}
err := sentry.Init(sentry.ClientOptions{
Dsn: sentryDSN,
Environment: sentryName,
Release: sentryVersion,
})
if err != nil {
NewLoggerPlain().Error().Err(err).Msg("sentry initialization failed")
return
}
initialized = true
}