Reporting handled errors

In order to quickly understand and fix some errors, it is often helpful to send additional diagnostic data which is specific to that error.

The bugsnag.Notify() function accepts several predefined options for customizing the error report.

bugsnag.Context

The context shows up prominently in the list view so that you can get an idea of where a problem occurred. You can set it by passing a bugsnag.Context object as rawData.

bugsnag.Notify(err, bugsnag.Context{"backgroundJob"})

bugsnag.ErrorClass

Errors in your Bugsnag dashboard are grouped by their “error class” and by line number. You can override the error class by passing a bugsnag.ErrorClass object as rawData.

bugsnag.Notify(err, bugsnag.ErrorClass{"I/O Timeout"})

bugsnag.MetaData

Custom metaData appears as tabs on Bugsnag.com. You can set it by passing a bugsnag.MetaData object as rawData.

bugsnag.Notify(err,
    bugsnag.MetaData{
        "Account": {
            "Name": Account.Name,
            "Paying": Account.Plan.Premium,
        },
    })

bugsnag.SeverityError, bugsnag.SeverityInfo, bugsnag.SeverityWarning

Bugsnag supports three severities, SeverityError, SeverityWarning, and SeverityInfo. You can set the severity of an error by passing one of these objects as rawData.

bugsnag.Notify(err, bugsnag.SeverityInfo)

bugsnag.User

User data is searchable, and the Id powers the count of users affected. You can set which user an error affects by passing a bugsnag.User object as rawData.

bugsnag.Notify(err, bugsnag.User{
    Id: "1234", Name: "Conrad", Email: "me@example.com"})

http.Request, revel.Controller

Bugsnag can extract interesting data from *http.Request objects, and *revel.Controller objects. These are automatically passed in when handling panics, and you can pass them yourself.

func (w http.ResponseWriter, r *http.Request) {
    bugsnag.Notify(err, r)
}