This week we released some improvements to our Go client, which reports panics and errors from Go applications. Check out the package on GitHub, and read on to learn about the update!
Before notification callbacks
One of the additions that we're most excited about is the honeybadger.BeforeNotify
callback, which allows you to ignore or modify error notifications as they occur. For example, you could ignore all errors of a specific type:
honeybadger.BeforeNotify(
func(notice *honeybadger.Notice) error {
if notice.ErrorClass == "SkippedError" {
return fmt.Errorf("Skipping this notification")
}
// Return nil to send notification for all other classes.
return nil
}
)
...or you could modify the error class for all errors:
honeybadger.BeforeNotify(
func(notice *honeybadger.Notice) error {
// Errors in Honeybadger will always have the class name "GenericError".
notice.ErrorClass = "GenericError"
return nil
}
)
Customizing error grouping
Honeybadger groups by the error type and the first line of the stack by default, but in some cases you may want to provide your own grouping strategy. In 0.0.2 we've made this possible by adding support for custom fingerprints. A fingerprint is simply a unique string; all errors that have the same fingerprint will be grouped together in Honeybadger.
A special case for a custom fingerprint in Go is errors.errorString
. Because that type is used for many different types of errors in Go, Honeybadger may appear to group unrelated errors together. To work around that, you could group errors.errorString
by message instead of type by customizing the fingerprint in a honeybadger.BeforeNotify
callback:
honeybadger.BeforeNotify(
func(notice *honeybadger.Notice) error {
if notice.ErrorClass == "errors.errorString" {
notice.Fingerprint = notice.Message
}
return nil
}
)
Note that in this example, the stack is ignored. If you want to group by message and stack, you could append data from notice.Backtrace
to the fingerprint string.
Custom notification improvements
If you've handled a panic in your code, but would still like to report the error to Honeybadger, you can use honeybadger.Notify
to report the error:
if err != nil {
honeybadger.Notify(err)
}
In 0.0.2, we've added some extra types which you can use with this API.
Overriding the error class name
Honeybadger uses the class name (in Go this is the type) of the error object to group similar errors together. If your types are often generic (such as errors.errorString
), you can improve grouping by overriding the default with our honeybadger.ErrorClass
type:
honeybadger.Notify(err, honeybadger.ErrorClass{"CustomClassName"})
Overriding the fingerprint
We also added a new honeybadger.Fingerprint
type which allows you to set the fingerprint locally:
honeybadger.Notify(err, honeybadger.Fingerprint{"A unique string"})
Note that any honeybadger.BeforeNotify
callbacks may also modify the fingerprint before the notification is sent.
Minor improvements and bugfixes
We also fixed some bugs and made some other minor feature improvements in 0.0.2. Speaking of which, we also added a CHANGELOG.
I hope that these improvements will help you exterminate errors and panics in your Go applications faster. If you haven't tried Honeybadger for Go yet, sign up for a free trial!