-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsentry_hook.go
59 lines (46 loc) · 1.15 KB
/
sentry_hook.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
package log
import (
"errors"
"fmt"
"io"
"os"
"time"
"github.com/getsentry/sentry-go"
jsoniter "github.com/json-iterator/go"
)
type sentryEvent struct {
Level string `json:"level"`
Msg string `json:"message"`
Err error `json:"error"`
Time time.Time `json:"time"`
Status int `json:"status,omitempty"`
UserAgent string `json:"user_agent,omitempty"`
Method string `json:"method,omitempty"`
URL string `json:"url,omitempty"`
IP string `json:"ip,omitempty"`
RequestID string `json:"request_id,omitempty"`
Action string `json:"action,omitempty"`
}
var errSkipEvent = errors.New("skip")
func sentryPush(hub *sentry.Hub, pr io.Reader) {
json := jsoniter.ConfigCompatibleWithStandardLibrary
dec := json.NewDecoder(pr)
for {
var e sentryEvent
err := dec.Decode(&e)
if errors.Is(err, io.EOF) {
return
}
if errors.Is(err, errSkipEvent) {
continue
}
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "unmarshaling logger failed with error %v\n", err)
continue
}
hub.CaptureException(e.Err)
}
}
func (s sentryEvent) Error() string {
return s.Err.Error()
}