forked from johnbellone/grpc-middleware-sentry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
55 lines (43 loc) · 1.12 KB
/
options.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
package grpc_sentry
import (
"time"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
const (
defaultServerOperationName = "grpc.server"
defaultClientOperationName = "grpc.client"
)
var defaultOptions = &options{
Repanic: false,
WaitForDelivery: false,
ReportOn: ReportAlways,
Timeout: 1 * time.Second,
OperationNameOverride: "",
CaptureRequestBody: true,
}
type options struct {
// Repanic configures whether Sentry should repanic after recovery.
Repanic bool
// WaitForDelivery configures whether you want to block the request before moving forward with the response.
WaitForDelivery bool
// Timeout for the event delivery requests.
Timeout time.Duration
ReportOn func(error) bool
OperationNameOverride string
// CaptureRequestBody configures whether the request body should be sent to Sentry.
CaptureRequestBody bool
}
func ReportAlways(error) bool {
return true
}
func ReportOnCodes(cc ...codes.Code) reporter {
return func(err error) bool {
for i := range cc {
if status.Code(err) == cc[i] {
return true
}
}
return false
}
}