Skip to content

Reducing noise

Sometimes you may want to modify the data sent to Honeybadger right before an error notification is sent, or skip the notification entirely. The honeybadger.BeforeNotify function lets you add callbacks to do this.

To skip certain errors from being reported, return an error from your BeforeNotify callback:

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
}
)

When your callback returns an error, the notification is not sent to Honeybadger.

You can also modify the notice before it’s sent. For example, to change 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
}
)

You can register multiple BeforeNotify callbacks. They will be executed in the order they were registered. If any callback returns an error, the notification is skipped.

The Notice struct passed to your callback contains these fields you can inspect or modify:

FieldTypeDescription
ErrorClassstringError type name
ErrorMessagestringError message
FingerprintstringGrouping fingerprint
Tags[]stringError tags
URLstringRequest URL
ContextContextCustom context data
ParamsParamsURL/form parameters
CGIDataCGIDataHTTP headers
Backtrace[]*FrameStack trace
EnvstringEnvironment name
HostnamestringServer hostname

See the Go package documentation for complete type definitions.

For development and testing, you may want to disable all error reporting. Use NewNullBackend to create a backend which swallows all errors:

honeybadger.Configure(honeybadger.Configuration{Backend: honeybadger.NewNullBackend()})

This is useful to prevent sending unnecessary errors during development or in test environments.