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.

context.Context

To track information per session (e.g. per HTTP request) the Go team advocates the context idiom.

BugSnag will automatically attach a context.Context to the revel.Controller.Args object, which can be retrieved through c.Args["context"].

If you’re outside the context of a HTTP request, e.g. inside a goroutine, you can call ctx = bugsnag.StartSession(ctx) to let BugSnag track your session.

go func() {
    ctx := bugsnag.StartSession(context.Background())
    defer bugsnag.AutoNotify(ctx)
    // goroutine logic...
    if err != nil {
        bugsnag.Notify(err, ctx)
    }
}()

If you wish to share the session between two goroutines you should pass the context to your goroutine function:

go func(ctx context) {
    defer bugsnag.AutoNotify(ctx)
    // goroutine logic...
    if err != nil {
        bugsnag.Notify(ctx, err)
    }
}(ctx)

bugsnag.Context

Note: This has no relation to the context.Context mentioned above.

The context shows up prominently in your BugSnag inbox 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, ctx, bugsnag.Context{String: "backgroundJob"})

See this reference to learn more about the ctx argument and the advantages of using it.

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, ctx, bugsnag.ErrorClass{Name: "I/O Timeout"})

See this reference to learn more about the ctx argument and the advantages of using it.

bugsnag.MetaData

Custom metaData appears as tabs in the BugSnag dashboard. You can set it by passing a bugsnag.MetaData object as rawData.

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

See this reference to learn more about the ctx argument and the advantages of using it.

bugsnag.Severity

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, ctx, bugsnag.SeverityInfo)

See this reference to learn more about the ctx argument and the advantages of using it.

bugsnag.User

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

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

See this reference to learn more about the ctx argument and the advantages of using it.