forked from utrack/health-sentry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsentry.go
85 lines (72 loc) · 1.84 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package health_sentry
import (
"github.com/getsentry/raven-go"
"github.com/gocraft/health"
)
// Sink emits errors to Sentry.
type Sink struct {
Config *Config
raven *raven.Client
}
type cmdEventErr struct {
Job string
Event string
Err *health.UnmutedError
Kvs map[string]string
}
// Config is used to configure Sentry sink.
type Config struct {
// Application's Sentry URL.
URL string
// Only send errors if set.
ErrorsOnly bool
}
// NewSink creates and returns new Sentry sink
// configured by given config.
func NewSink(config *Config) (*Sink, error) {
const maxChanSize = 25
epRaven, err := raven.NewClient(config.URL, nil)
if err != nil {
return nil, err
}
s := &Sink{
Config: config,
raven: epRaven,
}
return s, nil
}
func (s *Sink) EmitEvent(job string, event string, kvs map[string]string) {
// Ignore events if ErrorsOnly is set
if s.Config.ErrorsOnly {
return
}
packet := raven.NewPacket(job)
packet.Level = raven.INFO
kvs["event"] = event
s.raven.Capture(packet, kvs)
}
func (s *Sink) EmitEventErr(job string, event string, inputErr error, kvs map[string]string) {
switch inputErr := inputErr.(type) {
case *health.UnmutedError:
if !inputErr.Emitted {
packet := raven.NewPacket(job, raven.NewException((inputErr), raven.NewStacktrace(2, 3, nil)))
s.raven.Capture(packet, kvs)
}
case *health.MutedError:
// Do nothing!
default: // eg, case error:
// This shouldn't happen, all errors passed in here should be wrapped.
}
}
func (s *Sink) EmitTiming(job string, event string, nanos int64, kvs map[string]string) {
// no-op
}
func (s *Sink) EmitComplete(job string, status health.CompletionStatus, nanos int64, kvs map[string]string) {
// no-op
}
func (s *Sink) EmitGauge(job string, event string, value float64, kvs map[string]string) {
// no-op
}
func (s *Sink) ShutdownServer() {
s.raven.Close()
}