Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(stacktrace): Do not rely on AbsPath for filtering #123

Merged
merged 3 commits into from
Dec 17, 2019

Conversation

rhcarvalho
Copy link
Contributor

Fixes #100

@rhcarvalho rhcarvalho force-pushed the stacktrace branch 2 times, most recently from 400af95 to eb9ffee Compare December 13, 2019 19:29
TestContextifyFrames is concerned with answering "given a Frame, can we
load matching source code context?"

Therefore, it can perform its job independent of Trace/NewStacktrace.
NewStacktrace and ExtractStacktrace (through filterFrames) used to
whitelist stack frames of test and example files that are part of
sentry-go. That is likely only done to allow for testing.

However, by relying on the absolute path of files to perform the
filtering, the correct filtering of frames depended on how sentry-go was
checked out on disk. If the repository was checked out as part of a
traditional GOPATH tree, tests passed. If the repository was outside of
GOPATH, on an arbitraly named path (without a github.com/getsentry/
prefix), tests failed.

This commit replaces tests from stacktrace_test.go with new tests in
stacktrace_external_test.go. The difference being that the new tests are
built as a separate package. The separation is achieved by using the
ability to suffix the test package name with '_test'. See 'go help
test'.

This new test structure makes it easier to distinguish stack frames that
belong to the sentry-go SDK vs. stack frames that are part of the tests,
thus removing the need for path-pattern-based filtering.

The new tests make a more in-depth comparison of the stack frames
against expected values.

Now NewStacktrace and ExtractStacktrace filter out all the frames that
are part of the github.com/getsentry/sentry-go package/Module, without
looking at AbsPath.
@@ -3,6 +3,7 @@ linters:
disable:
- megacheck
- stylecheck
- funlen
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a "new" linter since we bumped the version of golangci-lint in #121. While I tend to prefer small functions, we should not be pleasing linters and discussing how many lines is small or not.
In particular, this linter complains about perfectly fine table test functions with a few test cases.

if strings.Contains(frame.AbsPath, "github.com/getsentry/sentry-go") &&
!isTestFile &&
!isExampleFile {
if frame.Module == "github.com/getsentry/sentry-go" {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a bit curious to me that a Frame has both a Module and a Package field. What do they mean exactly? I might have missed it, but it seemed like the Package field is never set. @kamilogorek for help 🆘

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rhcarvalho rhcarvalho marked this pull request as ready for review December 17, 2019 13:42
func stacktraceDiff(x, y *sentry.Stacktrace) string {
return cmp.Diff(
x, y,
cmpopts.IgnoreFields(sentry.Frame{}, "AbsPath"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, never seen it before

@kamilogorek kamilogorek self-requested a review December 17, 2019 13:56
Copy link
Contributor

@kamilogorek kamilogorek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually prefer tests that contain as few setup/run logic as possible, but in this case it fits nicely.

@rhcarvalho rhcarvalho merged commit b7a4515 into getsentry:master Dec 17, 2019
@rhcarvalho rhcarvalho deleted the stacktrace branch December 17, 2019 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failing tests when sentry-go is outside of GOPATH
2 participants