-
Notifications
You must be signed in to change notification settings - Fork 50
/
sentry.go
56 lines (45 loc) · 1.22 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
56
package log
import (
"fmt"
"time"
"github.com/getsentry/sentry-go"
"github.com/justtrackio/gosoline/pkg/cfg"
)
//go:generate mockery --name SentryHub
type SentryHub interface {
ConfigureScope(f func(scope *sentry.Scope))
WithScope(f func(scope *sentry.Scope))
CaptureException(exception error) *sentry.EventID
Flush(timeout time.Duration) bool
}
type SentryHubSettings struct {
Dsn string
Environment string
AppName string
}
func NewSentryHub(config cfg.Config) (SentryHub, error) {
settings := &SentryHubSettings{
Environment: config.GetString("env"),
AppName: config.GetString("app_name"),
}
return NewSentryHubWithSettings(settings)
}
func NewSentryHubWithSettings(settings *SentryHubSettings) (SentryHub, error) {
options := sentry.ClientOptions{
Dsn: settings.Dsn,
Environment: settings.Environment,
}
var err error
var client *sentry.Client
scope := sentry.NewScope()
if client, err = sentry.NewClient(options); err != nil {
return nil, fmt.Errorf("can not create sentry client: %w", err)
}
hub := sentry.NewHub(client, scope)
hub.ConfigureScope(func(scope *sentry.Scope) {
scope.SetTags(map[string]string{
"application": settings.AppName,
})
})
return hub, nil
}