kinbiko / bugsnag

Well-documented, maintainable, idiomatic, opinionated, and *unofficial* rewrite of the Bugsnag Go notifier
MIT License
3 stars 0 forks source link

Improve grouping algorithm #46

Closed kinbiko closed 2 years ago

kinbiko commented 2 years ago

Unlike the official bugsnag/bugsnag-go package, this package supports wrapping errors to form a "caused by exception" relationship in the dashboard. The default grouping algorithm looks only at the deepest exception (in Go: wrapped error) to find the top stackframe that's in-project. If there's no in-project stackframe in the deepest exception, whatever the top frame is will be used to group by. Unfortunately, most errors in the Go ecosystem don't have stacktraces attached (indeed it's a feature of the bugsnag.Error type in this package), so the errors will be grouped by a default stackframe that's auto-generated for exceptions without stacktraces. Not very helpful as this is >99.99% of errors...

This PR fixes this within the library by adding a grouping hash based on the filename and line number of the top in-project stackframe for the deepest error if it exists. I.e. if the deepest error does not have a stackframe in project (or a stackframe at all) then it will look at the second-deepest error, and so forth.

Additionally, this PR makes some tweaks to the example code to split into main and non-main packages, to get more useful data when testing manually.