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.
Skipping notifications
Section titled “Skipping notifications”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.
Modifying notifications
Section titled “Modifying notifications”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 })Multiple callbacks
Section titled “Multiple callbacks”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.
Notice fields
Section titled “Notice fields”The Notice
struct passed to your callback contains these fields you can inspect or modify:
| Field | Type | Description |
|---|---|---|
| ErrorClass | string | Error type name |
| ErrorMessage | string | Error message |
| Fingerprint | string | Grouping fingerprint |
| Tags | []string | Error tags |
| URL | string | Request URL |
| Context | Context | Custom context data |
| Params | Params | URL/form parameters |
| CGIData | CGIData | HTTP headers |
| Backtrace | []*Frame | Stack trace |
| Env | string | Environment name |
| Hostname | string | Server hostname |
See the Go package documentation for complete type definitions.
Disabling notifications entirely
Section titled “Disabling notifications entirely”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.