-
Notifications
You must be signed in to change notification settings - Fork 52
/
frame_matcher.go
50 lines (40 loc) · 1.06 KB
/
frame_matcher.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
package zapsentry
import (
"strings"
"github.com/getsentry/sentry-go"
)
type (
FrameMatchers []FrameMatcher
FrameMatcherFunc func(f sentry.Frame) bool
SkipModulePrefixFrameMatcher string
SkipFunctionPrefixFrameMatcher string
)
type FrameMatcher interface {
Matches(f sentry.Frame) bool
}
var (
defaultFrameMatchers = FrameMatchers{
SkipModulePrefixFrameMatcher("github.com/TheZeroSlave/zapsentry"),
SkipModulePrefixFrameMatcher("go.uber.org/zap"),
}
)
func (f FrameMatcherFunc) Matches(frame sentry.Frame) bool {
return f(frame)
}
func (f SkipModulePrefixFrameMatcher) Matches(frame sentry.Frame) bool {
return strings.HasPrefix(frame.Module, string(f))
}
func (f SkipFunctionPrefixFrameMatcher) Matches(frame sentry.Frame) bool {
return strings.HasPrefix(frame.Function, string(f))
}
func (ff FrameMatchers) Matches(frame sentry.Frame) bool {
for i := range ff {
if ff[i].Matches(frame) {
return true
}
}
return false
}
func CombineFrameMatchers(matcher ...FrameMatcher) FrameMatcher {
return FrameMatchers(matcher)
}