-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Just a refactoring, separate some structs to files
- Loading branch information
1 parent
309e5eb
commit 357843d
Showing
5 changed files
with
78 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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"), | ||
SkipFunctionPrefixFrameMatcher("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) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package zapsentry | ||
|
||
import "go.uber.org/zap/zapcore" | ||
|
||
type LevelEnabler struct { | ||
zapcore.LevelEnabler | ||
enableBreadcrumbs bool | ||
breadcrumbsLevel zapcore.LevelEnabler | ||
} | ||
|
||
func (l *LevelEnabler) Enabled(lvl zapcore.Level) bool { | ||
return l.LevelEnabler.Enabled(lvl) || (l.enableBreadcrumbs && l.breadcrumbsLevel.Enabled(lvl)) | ||
} |