Skip to content

Commit

Permalink
Merge pull request #15 from kerkerj/feature/filter-unnecessary-frames
Browse files Browse the repository at this point in the history
Filter internal/unnecessary frames
  • Loading branch information
TheZeroSlave authored Jan 25, 2021
2 parents db5f436 + 7877386 commit 7205c90
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions core.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package zapsentry

import (
"strings"
"time"

"github.com/getsentry/sentry-go"
Expand Down Expand Up @@ -53,6 +54,7 @@ func (c *core) Write(ent zapcore.Entry, fs []zapcore.Field) error {
if !c.cfg.DisableStacktrace {
trace := sentry.NewStacktrace()
if trace != nil {
trace.Frames = filterFrames(trace.Frames)
event.Exception = []sentry.Exception{{
Type: ent.Message,
Value: ent.Caller.TrimmedPath(),
Expand Down Expand Up @@ -122,3 +124,25 @@ type core struct {

fields map[string]interface{}
}

// follow same logic with sentry-go to filter unnecessary frames
// ref:
// https://github.com/getsentry/sentry-go/blob/362a80dcc41f9ad11c8df556104db3efa27a419e/stacktrace.go#L256-L280
func filterFrames(frames []sentry.Frame) []sentry.Frame {
if len(frames) == 0 {
return nil
}
filteredFrames := make([]sentry.Frame, 0, len(frames))

for i := range frames {
// Skip zapsentry and zap internal frames, except for frames in _test packages (for
// testing).
if (strings.HasPrefix(frames[i].Module, "github.com/TheZeroSlave/zapsentry") ||
strings.HasPrefix(frames[i].Function, "go.uber.org/zap")) &&
!strings.HasSuffix(frames[i].Module, "_test") {
break
}
filteredFrames = append(filteredFrames, frames[i])
}
return filteredFrames
}

0 comments on commit 7205c90

Please sign in to comment.