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.
Using honeybadger.Notify
Section titled “Using honeybadger.Notify”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)}Adding context to notifications
Section titled “Adding context to notifications”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.
Customizing error grouping
Section titled “Customizing error grouping”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.
Adding tags
Section titled “Adding tags”To tag errors in Honeybadger using
Tags:
honeybadger.Notify(err, honeybadger.Tags{"timeout", "http"})See Tagging errors for more details.
Combining options
Section titled “Combining options”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"},)Including HTTP request data
Section titled “Including HTTP request data”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.RequestFor more control, you can pass specific request data using
Params
and CGIData:
// Include URL parametershoneybadger.Notify(err, honeybadger.Params(r.URL.Query()))
// Include form datar.ParseForm()honeybadger.Notify(err, honeybadger.Params(r.Form))
// Include HTTP headers as CGI datahoneybadger.Notify(err, honeybadger.CGIData{ "REQUEST_METHOD": r.Method, "HTTP_USER_AGENT": r.UserAgent(), "REMOTE_ADDR": r.RemoteAddr,})
// Include the request URLhoneybadger.Notify(err, r.URL)Note: When using honeybadger.Handler, request data is captured
automatically. See the HTTP integration guide for
details.