-
Notifications
You must be signed in to change notification settings - Fork 157
/
sentry.go
53 lines (43 loc) · 974 Bytes
/
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
package sentry
import (
"context"
"fmt"
"github.com/getsentry/sentry-go"
)
type SentryAlerter struct {
client *sentry.Client
}
func noIntegrations(ints []sentry.Integration) []sentry.Integration {
return []sentry.Integration{}
}
type SentryAlerterOpts struct {
DSN string
Environment string
}
func NewSentryAlerter(opts *SentryAlerterOpts) (*SentryAlerter, error) {
sentryClient, err := sentry.NewClient(sentry.ClientOptions{
Dsn: opts.DSN,
AttachStacktrace: true,
Integrations: noIntegrations,
Environment: opts.Environment,
})
if err != nil {
return nil, err
}
return &SentryAlerter{
client: sentryClient,
}, nil
}
func (s *SentryAlerter) SendAlert(ctx context.Context, err error, data map[string]interface{}) {
scope := sentry.NewScope()
for key, val := range data {
scope.SetTag(key, fmt.Sprintf("%v", val))
}
s.client.CaptureException(
err,
&sentry.EventHint{
Data: data,
},
scope,
)
}