/
alerts.go
78 lines (65 loc) · 1.69 KB
/
alerts.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
package alerts
import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/puppetlabs/leg/instrumentation/alerts/internal/noop"
"github.com/puppetlabs/leg/instrumentation/alerts/internal/passthrough"
"github.com/puppetlabs/leg/instrumentation/alerts/internal/sentry"
"github.com/puppetlabs/leg/instrumentation/alerts/internal/sns"
"github.com/puppetlabs/leg/instrumentation/alerts/trackers"
"github.com/puppetlabs/leg/instrumentation/errors"
)
type Options struct {
Environment string
Version string
}
type DelegateFunc func(opts Options) Delegate
func NoDelegate(opts Options) Delegate {
return &noop.NoOp{}
}
func DelegateToPassthrough() (DelegateFunc, errors.Error) {
b, err := passthrough.NewBuilder()
if err != nil {
return nil, err
}
fn := func(opts Options) Delegate {
return b.WithEnvironment(opts.Environment).
WithRelease(opts.Version).
Build()
}
return fn, nil
}
func DelegateToSNS(arn string, sopts session.Options) (DelegateFunc, errors.Error) {
b, err := sns.NewBuilder(arn, sopts)
if err != nil {
return nil, err
}
fn := func(opts Options) Delegate {
return b.WithEnvironment(opts.Environment).
WithRelease(opts.Version).
Build()
}
return fn, nil
}
func DelegateToSentry(dsn string) (DelegateFunc, errors.Error) {
b, err := sentry.NewBuilder(dsn)
if err != nil {
return nil, err
}
fn := func(opts Options) Delegate {
return b.WithEnvironment(opts.Environment).
WithRelease(opts.Version).
Build()
}
return fn, nil
}
type Alerts struct {
delegate Delegate
}
func (a *Alerts) NewCapturer() trackers.Capturer {
return a.delegate.NewCapturer()
}
func NewAlerts(fn DelegateFunc, opts Options) *Alerts {
return &Alerts{
delegate: fn(opts),
}
}