Configuration options

To configure BugSnag for your Revel application, you can either call bugsnag.Configure at the start of your application, or set configuration options in your conf/app.conf file. For bugsnag.Configure you pass it a bugsnag.Configuration object containing any of the following values.

The only required configuration is the BugSnag API key which can be obtained by clicking “Settings” on the top of of your BugSnag dashboard after signing up. We also recommend you set the ReleaseStage, AppType, and AppVersion if these make sense for your deployment workflow.

APIKey

You can find your API key in Project Settings from your BugSnag dashboard.

To configure this property, set bugsnag.apikey in your conf/app.conf:

bugsnag.apikey = YOUR_API_KEY_HERE

Alternatively, you can do this configuration using bugsnag.Configure():

bugsnag.Configure(bugsnag.Configuration{
    APIKey: "YOUR_API_KEY_HERE",
})

If you want to have multiple different configurations around in one program, you can use bugsnag.New() to create multiple independent instances of BugSnag.

notifier := bugsnag.New(bugsnag.Configuration{
    APIKey: "YOUR_OTHER_API_KEY",
})

AppType

If your app has multiple components with different configurations, it can be useful when filtering error reports to separate them by the type of app, like HTTP router, worker queues, and more.

To configure this property, set bugsnag.apptype in your conf/app.conf:

bugsnag.apptype = queue

Alternatively, you can do this configuration using bugsnag.Configure():

bugsnag.Configure(bugsnag.Configuration{
    AppType: "queue",
})

The default app type is ‘Revel’.

AppVersion

If you use a versioning scheme for deploys of your app, BugSnag can use the AppVersion to track your releases and only re-open errors if they occur in later version of the app.

To configure this property, set bugsnag.appversion in your conf/app.conf:

bugsnag.appversion = 1.2.3

Alternatively, you can do this configuration using bugsnag.Configure():

bugsnag.Configure(bugsnag.Configuration{
    AppVersion: "1.2.3",
})

AutoCaptureSessions

By default, BugSnag will automatically capture and report session information from your application. Use this flag to disable all automatic reporting.

To configure this property, set bugsnag.autocapturesessions in your conf/app.conf:

bugsnag.autocapturesessions = false

Alternatively, you can do this configuration using bugsnag.Configure():

bugsnag.Configure(bugsnag.Configuration{
    AutoCaptureSessions: false,
})

If you want control over what is deemed a session, you can switch off automatic session tracking with the above configuration, and call bugsnag.StartSession() when appropriate for your application.

Endpoints

By default we will send error reports to notify.bugsnag.com and sessions to sessions.bugsnag.com.

If you are using BugSnag On-premise you’ll need to set these to your Event Server and Session Server endpoints. If the notify endpoint is set but the sessions endpoint is not, session tracking will be disabled automatically to avoid leaking session information outside of your server configuration, and a warning will be logged.

To configure these properties, set bugsnag.endpoints in your conf/app.conf:

bugsnag.endpoints.notify = "http://bugsnag.internal:49000/"
bugsnag.endpoints.sessions = "http://bugsnag.internal:49001/"

Alternatively, you can do this configuration using bugsnag.Configure():

bugsnag.Configure(bugsnag.Configuration{
    Endpoints: bugsnag.Endpoints{
        Notify:   "http://bugsnag.internal:49000/",
        Sessions: "http://bugsnag.internal:49001/",
    }
})

Hostname

The hostname is used to track where errors are coming from in the BugSnag dashboard. The default value is obtained from os.Hostname() so you won’t often need to change this.

To configure this property, set bugsnag.hostname in your conf/app.conf:

bugsnag.hostname = go1

Alternatively, you can do this configuration using bugsnag.Configure():

bugsnag.Configure(bugsnag.Configuration{
    Hostname: "go1",
})

Logger

By default, the notifier’s log messages will be logged using a wrapper around revel.AppLog.

You can override this by setting the Logger configuration option in code:

bugsnag.Configure(bugsnag.Configuration{
    Logger: app.Logger,
}

NotifyReleaseStages

The list of release stages to notify in. By default BugSnag will notify you in all release stages, but you can use this to silence development errors.

To configure this property, set bugsnag.notifyreleasestages in your conf/app.conf:

bugsnag.notifyreleasestages=production,staging

Alternatively, you can do this configuration using bugsnag.Configure():

bugsnag.Configure(bugsnag.Configuration{
    NotifyReleaseStages: []string{"production", "staging"},
})

OnBeforeNotify

Add callbacks to modify or discard error events before they are sent to BugSnag. To cancel an event, return an error from the callback.

Custom structures passed to Notify are available in the RawData of the event within the callback. The RawData itself is not delivered as a part of the event, but can be accessed to add information when available.

bugsnag.OnBeforeNotify(
    func(event *bugsnag.Event, config *bugsnag.Configuration) error {
        for _, datum := range event.RawData {
            if user, ok := datum.(*MyUserInfo); ok {
                event.User = &User{Id: user.Id}
            }
        }
    })

If you are not using panic-monitor, all OnBeforeNotify callbacks must be registered prior to calling Configure() or will have no effect on events created from unrecovered panics. Panic handling in bugsnag-go forks the process when Configure() is first called, so any callbacks added after that point will not be present in the monitoring process. See the Reporting unhandled panics guide for more information.

Detailed example with custom metadata and conditional cancellation

For example, lets say our system processes jobs:

type Job struct{
    Retry     bool
    UserId    string
    Name      string
    Params    map[string]string
}

You can pass a job directly into bugsnag.Notify:

bugsnag.Notify(err, c.Args["context"], job)

And then add a filter to extract information from that job and attach it to the BugSnag event:

bugsnag.OnBeforeNotify(
    func(event *bugsnag.Event, config *bugsnag.Configuration) error {

        // Search all the RawData for any *Job pointers that we're passed in
        // to bugsnag.Notify() and friends.
        for _, datum := range event.RawData {
            if job, ok := datum.(*Job); ok {
                // don't notify bugsnag about errors in retries
                if job.Retry {
                    return fmt.Errorf("not notifying about retried jobs")
                }

                // add the job as a tab in the BugSnag dashboard
                event.MetaData.AddStruct("Job", job)

                // set the user correctly
                event.User = &User{Id: job.UserId, Email: job.UserEmail}
            }
        }

        // continue notifying as normal
        return nil
    })

See Customizing error reports for more examples and a list of available Event properties.

PanicHandler

The first time BugSnag is configured, it wraps the running program in a panic handler using panicwrap. This forks a sub-process which monitors unhandled panics. To prevent this, set PanicHandler to func() {} the in a call to bugsnag.Configure in a revel.OnAppStart(). This will prevent bugsnag from being able to notify you about fatal panics.

revel.OnAppStart(func() {
    bugsnag.Configure(bugsnag.Configuration{
        PanicHandler: func() {},
    })
})

ParamsFilters

Sometimes sensitive data is accidentally included in BugSnag MetaData. You can remove it by setting ParamsFilters. Any key in the MetaData that includes any string in the filters will be redacted. The default is []string{"password", "secret", "authorization", "cookie"}, which prevents fields like password, password_confirmation and secret_answer from being sent.

ParamsFilters also filters out to request headers.

To configure this property, set bugsnag.paramsfilters in your conf/app.conf:

bugsnag.paramsfilters=password,secret

Alternatively, you can do this configuration using bugsnag.Configure():

bugsnag.Configure(bugsnag.Configuration{
    ParamsFilters: []string{"password", "secret"},
}

ProjectPackages

In order to determine where a crash happens BugSnag needs to know which packages you consider to be part of your app (as opposed to a library). By default this is set to []string{revel.ImportPath + "/app/**"}. Strings are matched to package names using filepath.Match.

For matching subpackages within a package you may use the ** notation. For example, github.com/domain/package/** will match all subpackages under package/.

To configure this property, set bugsnag.projectpackages in your conf/app.conf:

bugsnag.projectpackages=github.com/myorg/myapp/*,github.com/myorg/common/*

Alternatively, you can do this configuration using bugsnag.Configure():

bugsnag.Configure(bugsnag.Configuration{
    ProjectPackages: []string{"github.com/myorg/myapp/*", "github.com/myorg/common/*"},
}

ReleaseStage

The release stage tracks where your app is deployed. You should set this to production, staging, development or similar as appropriate.

To configure this property, set bugsnag.releasestage in your conf/app.conf:

bugsnag.releasestage = development

Alternatively, you can do this configuration using bugsnag.Configure():

bugsnag.Configure(bugsnag.Configuration{
    ReleaseStage: "development",
})

By default, this value will be revel.RunMode.

SourceRoot

The directory where source packages are built and the assumed prefix of package directories. When set, the prefix is trimmed from callstack frame file names before ProjectPackages are stripped, for better readability and error grouping on the BugSnag dashboard. The default value is $GOPATH/src or $GOROOT/src if $GOPATH is unset. At runtime, $GOROOT is the root used during the Go build. See the Go runtime package documentation for more information

To configure this property, set bugsnag.sourceroot in your conf/app.conf:

bugsnag.sourceroot = /my/source/root/

Alternatively, you can do this configuration using bugsnag.Configure():

bugsnag.Configure(bugsnag.Configuration{
    SourceRoot: "/my/source/root",
})

Synchronous

BugSnag usually starts a new goroutine before sending notifications. This means that notifications can be lost if you do a bugsnag.Notify and then immediately os.Exit. To avoid this problem, set BugSnag to Synchronous.

To configure this property, set bugsnag.synchronous in your conf/app.conf:

bugsnag.synchronous = true

Alternatively, you can do this configuration using bugsnag.Configure():

bugsnag.Configure(bugsnag.Configuration{
    Synchronous: true,
})

Or just for one error:

bugsnag.Notify(err, bugsnag.Configuration{Synchronous: true})

Transport

The transport configures how BugSnag makes HTTP requests. By default we use http.DefaultTransport which handles HTTP proxies automatically using the $HTTP_PROXY environment variable.

bugsnag.Configure(bugsnag.Configuration{
    Transport: http.DefaultTransport,
})