Skip to content

Reporting errors

Honeybadger reports unhandled panics automatically when you use honeybadger.Handler or honeybadger.Monitor(). In all other cases, use honeybadger.Notify to send errors to Honeybadger.

If you’ve handled a panic in your code, but would still like to report the error to Honeybadger, use honeybadger.Notify:

if err != nil {
honeybadger.Notify(err)
}

You can add local context using an optional second argument with Context:

honeybadger.Notify(err, honeybadger.Context{"user_id": 2})

See Adding context to errors for more details.

Honeybadger uses the error’s class name to group similar errors together. If your error classes are often generic (such as errors.errorString), you can improve grouping by overriding the default with ErrorClass:

honeybadger.Notify(err, honeybadger.ErrorClass{"CustomClassName"})

To override grouping entirely, you can send a custom Fingerprint. All errors with the same fingerprint will be grouped together:

honeybadger.Notify(err, honeybadger.Fingerprint{"A unique string"})

See Customizing error grouping for more details.

To tag errors in Honeybadger using Tags:

honeybadger.Notify(err, honeybadger.Tags{"timeout", "http"})

See Tagging errors for more details.

You can combine multiple options in a single Notify call:

honeybadger.Notify(err,
honeybadger.Context{"user_id": 2},
honeybadger.Tags{"timeout", "http"},
honeybadger.ErrorClass{"TimeoutError"},
)

When reporting errors from HTTP handlers, you can pass the request directly to include URL, parameters, and headers automatically:

honeybadger.Notify(err, r) // r is *http.Request

For more control, you can pass specific request data using Params and CGIData:

// Include URL parameters
honeybadger.Notify(err, honeybadger.Params(r.URL.Query()))
// Include form data
r.ParseForm()
honeybadger.Notify(err, honeybadger.Params(r.Form))
// Include HTTP headers as CGI data
honeybadger.Notify(err, honeybadger.CGIData{
"REQUEST_METHOD": r.Method,
"HTTP_USER_AGENT": r.UserAgent(),
"REMOTE_ADDR": r.RemoteAddr,
})
// Include the request URL
honeybadger.Notify(err, r.URL)

Note: When using honeybadger.Handler, request data is captured automatically. See the HTTP integration guide for details.