-
Notifications
You must be signed in to change notification settings - Fork 5
/
sentry.go
55 lines (48 loc) · 1.1 KB
/
sentry.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
package config
import (
"log/slog"
"github.com/getsentry/sentry-go"
"github.com/m-mizutani/goerr"
"github.com/m-mizutani/octovy/pkg/utils"
"github.com/urfave/cli/v2"
)
type Sentry struct {
dsn string
env string
}
func (x *Sentry) Flags() []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "sentry-dsn",
Usage: "Sentry DSN for error reporting",
EnvVars: []string{"OCTOVY_SENTRY_DSN"},
Destination: &x.dsn,
},
&cli.StringFlag{
Name: "sentry-env",
Usage: "Sentry environment",
EnvVars: []string{"OCTOVY_SENTRY_ENV"},
Destination: &x.env,
},
}
}
func (x *Sentry) Configure() error {
if x.dsn != "" {
utils.Logger().Info("Enable Sentry", "DSN", x.dsn, "env", x.env)
if err := sentry.Init(sentry.ClientOptions{
Dsn: x.dsn,
Environment: x.env,
}); err != nil {
return goerr.Wrap(err, "failed to initialize Sentry")
}
} else {
utils.Logger().Warn("sentry is not enabled")
}
return nil
}
func (x *Sentry) LogValue() slog.Value {
return slog.GroupValue(
slog.String("dsn", x.dsn),
slog.String("env", x.env),
)
}