-
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.
feat: add FrameMatcher config option (#23)
This allows to remove any kind of frame from the stacktrace sent to Sentry e.g. if zap is used in combination with go-logr.
- Loading branch information
Showing
4 changed files
with
185 additions
and
26 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,93 @@ | ||
package zapsentry | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/getsentry/sentry-go" | ||
) | ||
|
||
func Test_core_filterFrames(t *testing.T) { | ||
t.Parallel() | ||
type args struct { | ||
frames []sentry.Frame | ||
} | ||
tests := []struct { | ||
name string | ||
matcher FrameMatcher | ||
args args | ||
wantRemainingFrames int | ||
}{ | ||
{ | ||
name: "Empty filter set - do not filter anything at all", | ||
matcher: FrameMatchers{}, | ||
args: args{ | ||
[]sentry.Frame{ | ||
{ | ||
Module: "github.com/TheZeroSlave/zapsentry", | ||
}, | ||
}, | ||
}, | ||
wantRemainingFrames: 1, | ||
}, | ||
{ | ||
name: "Default filter set - filter frames from zapsentry", | ||
matcher: defaultFrameMatchers, | ||
args: args{ | ||
[]sentry.Frame{ | ||
{ | ||
Module: "github.com/TheZeroSlave/zapsentry", | ||
}, | ||
{ | ||
Module: "github.com/TheZeroSlave/zapsentry/someinternal", | ||
}, | ||
}, | ||
}, | ||
wantRemainingFrames: 0, | ||
}, | ||
{ | ||
name: "Default filter set - filter frames from zap", | ||
matcher: defaultFrameMatchers, | ||
args: args{ | ||
[]sentry.Frame{ | ||
{ | ||
Function: "go.uber.org/zap/String", | ||
}, | ||
}, | ||
}, | ||
wantRemainingFrames: 0, | ||
}, | ||
{ | ||
name: "Custom filter - ignore if test file", | ||
matcher: FrameMatcherFunc(func(f sentry.Frame) bool { | ||
return strings.HasSuffix(f.Filename, "_test.go") | ||
}), | ||
args: args{ | ||
[]sentry.Frame{ | ||
{ | ||
Filename: "core_test.go", | ||
}, | ||
{ | ||
Filename: "core.go", | ||
}, | ||
}, | ||
}, | ||
wantRemainingFrames: 1, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
c := &core{ | ||
cfg: &Configuration{ | ||
FrameMatcher: tt.matcher, | ||
}, | ||
} | ||
got := c.filterFrames(tt.args.frames) | ||
if len(got) != tt.wantRemainingFrames { | ||
t.Errorf("filterFrames() = %v, want %v", got, tt.wantRemainingFrames) | ||
} | ||
}) | ||
} | ||
} |
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