Skip to content

Commit bf38760

Browse files
committed
fix(stacktrace): Ignore SDK subpackage frames
Compared to release v0.3.1, now filteredFrames compares the frame.Module value instead of frame.AbsPath, and ignores SDK "_test" packages instead of pattern matching test files and examples. However confusing it might be, frame.Module holds a package name, unrelated to Go Modules. This fixes up the regression introduced in 61d7ccc, which caused frames from integrations/subpackages to be reported to Sentry.
1 parent 43729e5 commit bf38760

File tree

2 files changed

+105
-4
lines changed

2 files changed

+105
-4
lines changed

stacktrace.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,24 @@ func extractFrames(pcs []uintptr) []Frame {
206206
return frames
207207
}
208208

209+
// filterFrames filters out stack frames that are not meant to be reported to
210+
// Sentry. Those are frames internal to the SDK or Go.
209211
func filterFrames(frames []Frame) []Frame {
212+
if len(frames) == 0 {
213+
return nil
214+
}
215+
210216
filteredFrames := make([]Frame, 0, len(frames))
211217

212218
for _, frame := range frames {
213-
// go runtime frames
219+
// Skip Go internal frames.
214220
if frame.Module == "runtime" || frame.Module == "testing" {
215221
continue
216222
}
217-
// sentry internal frames
218-
if frame.Module == "github.com/getsentry/sentry-go" ||
219-
strings.HasPrefix(frame.Module, "github.com/getsentry/sentry-go.") {
223+
// Skip Sentry internal frames, except for frames in _test packages (for
224+
// testing).
225+
if strings.HasPrefix(frame.Module, "github.com/getsentry/sentry-go") &&
226+
!strings.HasSuffix(frame.Module, "_test") {
220227
continue
221228
}
222229
filteredFrames = append(filteredFrames, frame)

stacktrace_test.go

+94
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,97 @@ func TestSplitQualifiedFunctionName(t *testing.T) {
6565
})
6666
}
6767
}
68+
69+
//nolint: scopelint // false positive https://github.com/kyoh86/scopelint/issues/4
70+
func TestFilterFrames(t *testing.T) {
71+
tests := []struct {
72+
in []Frame
73+
out []Frame
74+
}{
75+
// sanity check
76+
{},
77+
// filter out go internals and SDK internals; "sentry-go_test" is
78+
// considered outside of the SDK and thus included (useful for testing)
79+
{
80+
in: []Frame{
81+
{
82+
Function: "goexit",
83+
Module: "runtime",
84+
AbsPath: "/goroot/src/runtime/asm_amd64.s",
85+
InApp: false,
86+
},
87+
{
88+
Function: "tRunner",
89+
Module: "testing",
90+
AbsPath: "/goroot/src/testing/testing.go",
91+
InApp: false,
92+
},
93+
{
94+
Function: "TestNewStacktrace.func1",
95+
Module: "github.com/getsentry/sentry-go_test",
96+
AbsPath: "/somewhere/sentry/sentry-go/stacktrace_external_test.go",
97+
InApp: true,
98+
},
99+
{
100+
Function: "StacktraceTestHelper.NewStacktrace",
101+
Module: "github.com/getsentry/sentry-go",
102+
AbsPath: "/somewhere/sentry/sentry-go/stacktrace_test.go",
103+
InApp: true,
104+
},
105+
{
106+
Function: "NewStacktrace",
107+
Module: "github.com/getsentry/sentry-go",
108+
AbsPath: "/somewhere/sentry/sentry-go/stacktrace.go",
109+
InApp: true,
110+
},
111+
},
112+
out: []Frame{
113+
{
114+
Function: "TestNewStacktrace.func1",
115+
Module: "github.com/getsentry/sentry-go_test",
116+
AbsPath: "/somewhere/sentry/sentry-go/stacktrace_external_test.go",
117+
InApp: true,
118+
},
119+
},
120+
},
121+
// filter out integrations; SDK subpackages
122+
{
123+
in: []Frame{
124+
{
125+
Function: "Example.Integration",
126+
Module: "github.com/getsentry/sentry-go/http/integration",
127+
AbsPath: "/somewhere/sentry/sentry-go/http/integration/integration.go",
128+
InApp: true,
129+
},
130+
{
131+
Function: "(*Handler).Handle",
132+
Module: "github.com/getsentry/sentry-go/http",
133+
AbsPath: "/somewhere/sentry/sentry-go/http/sentryhttp.go",
134+
InApp: true,
135+
},
136+
{
137+
Function: "main",
138+
Module: "main",
139+
AbsPath: "/somewhere/example.com/pkg/main.go",
140+
InApp: true,
141+
},
142+
},
143+
out: []Frame{
144+
{
145+
Function: "main",
146+
Module: "main",
147+
AbsPath: "/somewhere/example.com/pkg/main.go",
148+
InApp: true,
149+
},
150+
},
151+
},
152+
}
153+
for _, tt := range tests {
154+
t.Run("", func(t *testing.T) {
155+
got := filterFrames(tt.in)
156+
if diff := cmp.Diff(tt.out, got); diff != "" {
157+
t.Errorf("filterFrames() mismatch (-want +got):\n%s", diff)
158+
}
159+
})
160+
}
161+
}

0 commit comments

Comments
 (0)