Revel integration guide

Add Bugsnag to your Revel applications.

Installation

Download the code via go get:

go get github.com/bugsnag/bugsnag-go

Basic configuration

There are two steps to get panic handling in Revel apps.

  1. Add the bugsnagrevel.Filter immediately after the revel.PanicFilter in app/init.go:

    
    import "github.com/bugsnag/bugsnag-go/revel"
    
    revel.Filters = []revel.Filter{
        revel.PanicFilter,
        bugsnagrevel.Filter,
        // ...
    }
    
  2. Set bugsnag.apikey in the top section of conf/app.conf.

    module.static=github.com/revel/revel/modules/static
    
    bugsnag.apikey=YOUR_API_KEY_HERE
    
    [dev]
    

Reporting unhandled exceptions

After completing installation and basic configuration, unhandled exceptions will be automatically reported. Error data will begin to appear in your project’s dashboard.

This feature is enabled via Configuration.PanicHandler, which forks and monitors the application as a sub-process, reporting any unhandled panics.

Reporting handled exceptions

Sometimes it is useful to manually notify Bugsnag of a problem. To do this, call bugsnag.Notify()

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

Manual Panic Handling

To avoid a panic in a goroutine from crashing your entire app, you can use bugsnag.Recover() to stop a panic from unwinding the stack any further. When Recover() is hit, it will send any current panic to Bugsnag and then stop panicking. This is most useful at the start of a goroutine:

go func() {
    defer bugsnag.Recover()

    // ...
}()

Alternatively you can use bugsnag.AutoNotify() to notify bugsnag of a panic while letting the program continue to panic. This is useful if you’re using a framework that already has some handling of panics and you are retrofitting Bugsnag support.

defer bugsnag.AutoNotify()

When reporting handled exceptions, it’s often helpful to send us custom diagnostic data or to adjust the severity of particular errors. For more information, see the reporting handled errors reference.

Sending diagnostic data

Most functions in the Bugsnag API, including bugsnag.Notify(), bugsnag.Recover(), bugsnag.AutoNotify(), and bugsnag.Handler() let you attach data to the notifications that they send. To do this you pass in rawData, which can be any of the supported types listed here.

Custom metaData appears as tabs on error reports on your Bugsnag dashboard. 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,
        },
    })

For more information, see the reporting handled errors reference.

Identifying users

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"})

For more information, see the reporting handled errors reference.

Tracking deploys

By sending your source revision or application version when you deploy a new version, you’ll be able to see in which deployment each error was introduced and link stacktrace lines with the related code on GitHub.

Integrate a call to our deploy tracking API into your deployment process.

Next steps