@@ -3,7 +3,6 @@ package zapsentry
33import (
44 "errors"
55 "reflect"
6- "strings"
76 "time"
87
98 "github.com/getsentry/sentry-go"
@@ -20,48 +19,8 @@ const (
2019
2120var (
2221 ErrInvalidBreadcrumbLevel = errors .New ("breadcrumb level must be lower than or equal to error level" )
23-
24- defaultFrameMatchers = FrameMatchers {
25- SkipModulePrefixFrameMatcher ("github.com/TheZeroSlave/zapsentry" ),
26- SkipFunctionPrefixFrameMatcher ("go.uber.org/zap" ),
27- }
28- )
29-
30- type (
31- FrameMatcher interface {
32- Matches (f sentry.Frame ) bool
33- }
34- FrameMatchers []FrameMatcher
35- FrameMatcherFunc func (f sentry.Frame ) bool
36- SkipModulePrefixFrameMatcher string
37- SkipFunctionPrefixFrameMatcher string
3822)
3923
40- func (f FrameMatcherFunc ) Matches (frame sentry.Frame ) bool {
41- return f (frame )
42- }
43-
44- func (f SkipModulePrefixFrameMatcher ) Matches (frame sentry.Frame ) bool {
45- return strings .HasPrefix (frame .Module , string (f ))
46- }
47-
48- func (f SkipFunctionPrefixFrameMatcher ) Matches (frame sentry.Frame ) bool {
49- return strings .HasPrefix (frame .Function , string (f ))
50- }
51-
52- func (ff FrameMatchers ) Matches (frame sentry.Frame ) bool {
53- for i := range ff {
54- if ff [i ].Matches (frame ) {
55- return true
56- }
57- }
58- return false
59- }
60-
61- func CombineFrameMatchers (matcher ... FrameMatcher ) FrameMatcher {
62- return FrameMatchers (matcher )
63- }
64-
6524func NewScopeFromScope (scope * sentry.Scope ) zapcore.Field {
6625 f := zap .Skip ()
6726 f .Interface = scope
@@ -88,18 +47,19 @@ func NewCore(cfg Configuration, factory SentryClientFactory) (zapcore.Core, erro
8847 cfg .MaxBreadcrumbs = defaultMaxBreadcrumbs
8948 }
9049
91- // copy default values to avoid accidental modification
50+ // copy default values to prevent accidental modification.
9251 matchers := make (FrameMatchers , len (defaultFrameMatchers ), len (defaultFrameMatchers )+ 1 )
9352 copy (matchers , defaultFrameMatchers )
9453
95- switch m := cfg .FrameMatcher .(type ) {
96- case nil :
97- cfg .FrameMatcher = matchers
98- case FrameMatchers :
99- // in case the configured matcher was already a collection, append the default ones to avoid nested looping
100- cfg .FrameMatcher = append (matchers , m ... )
101- default :
54+ if cfg .FrameMatcher != nil {
10255 cfg .FrameMatcher = append (matchers , cfg .FrameMatcher )
56+ } else {
57+ cfg .FrameMatcher = matchers
58+ }
59+
60+ var flushTimeout = time .Second * 5
61+ if cfg .FlushTimeout > 0 {
62+ flushTimeout = cfg .FlushTimeout
10363 }
10464
10565 core := core {
@@ -110,14 +70,10 @@ func NewCore(cfg Configuration, factory SentryClientFactory) (zapcore.Core, erro
11070 breadcrumbsLevel : cfg .BreadcrumbLevel ,
11171 enableBreadcrumbs : cfg .EnableBreadcrumbs ,
11272 },
113- flushTimeout : 5 * time . Second ,
73+ flushTimeout : flushTimeout ,
11474 fields : make (map [string ]interface {}),
11575 }
11676
117- if cfg .FlushTimeout > 0 {
118- core .flushTimeout = cfg .FlushTimeout
119- }
120-
12177 return & core , nil
12278}
12379
@@ -138,8 +94,7 @@ func (c *core) Check(ent zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.Check
13894func (c * core ) Write (ent zapcore.Entry , fs []zapcore.Field ) error {
13995 clone := c .with (c .addSpecialFields (ent , fs ))
14096
141- // only when we have local sentryScope to avoid collecting all breadcrumbs ever in a global scope
142- if c .cfg .EnableBreadcrumbs && c .cfg .BreadcrumbLevel .Enabled (ent .Level ) && c .scope () != nil {
97+ if c .cfg .EnableBreadcrumbs && c .cfg .BreadcrumbLevel .Enabled (ent .Level ) {
14398 breadcrumb := sentry.Breadcrumb {
14499 Message : ent .Message ,
145100 Data : clone .fields ,
@@ -363,10 +318,6 @@ func (c *core) with(fs []zapcore.Field) *core {
363318 }
364319}
365320
366- type ClientGetter interface {
367- GetClient () * sentry.Client
368- }
369-
370321func (c * core ) GetClient () * sentry.Client {
371322 return c .client
372323}
@@ -404,13 +355,3 @@ func (c *core) filterFrames(frames []sentry.Frame) []sentry.Frame {
404355
405356 return frames
406357}
407-
408- type LevelEnabler struct {
409- zapcore.LevelEnabler
410- enableBreadcrumbs bool
411- breadcrumbsLevel zapcore.LevelEnabler
412- }
413-
414- func (l * LevelEnabler ) Enabled (lvl zapcore.Level ) bool {
415- return l .LevelEnabler .Enabled (lvl ) || (l .enableBreadcrumbs && l .breadcrumbsLevel .Enabled (lvl ))
416- }
0 commit comments