Configuration options

You must call bugsnag.Configure() at the start of your program to use Bugsnag, you pass it a bugsnag.Configuration object containing any of the following values.

APIKey

The Bugsnag API key can be found on your Bugsnag dashboard under “Settings”.

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. You can use these without calling bugsnag.Configure(), but bear in mind that until you call bugsnag.Configure() unhandled panics will not be sent to Bugsnag.

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

Any place that lets you pass in rawData also allows you to pass in configuration. For example, to send HTTP errors to one Bugsnag project:

bugsnag.Handler(nil, bugsnag.Configuration{APIKey: "YOUR_OTHER_API_KEY"})

AppVersion

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

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

Endpoint

The Bugsnag endpoint defaults to https://notify.bugsnag.com/. If you’re using Bugsnag enterprise, you should set this to the endpoint of your local instance.

bugsnag.Configure(bugsnag.Configuration{
    Endpoint: "http://bugsnag.internal:49000/",
})

GroupingHash

If you need to override Bugsnag’s grouping algorithm, you can set the GroupingHash in an OnBeforeNotify:

bugsnag.OnBeforeNotify(
    func (event *bugsnag.Event, config *bugsnag.Configuration) error {
        event.GroupingHash = calculateGroupingHash(event)
        return nil
    })

Hostname

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

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

Logger

The Logger to write to in case of an error inside Bugsnag. This defaults to the global logger.

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

NotifyReleaseStages

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

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

OnBeforeNotify

While it’s nice that you can pass MetaData directly into bugsnag.Notify, bugsnag.AutoNotify, and bugsnag.Recover, this can be a bit cumbersome and inefficient — you’re constructing the meta-data whether or not it will actually be used. A better idea is to pass raw data in to these functions, and add an OnBeforeNotify filter that converts them into MetaData.

For example, lets say our system processes jobs:

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

You can pass a job directly into Bugsnag.notify:

bugsnag.Notify(err, 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 on Bugsnag.com
                event.MetaData.AddStruct("Job", job)

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

        // continue notifying as normal
        return nil
    })

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 first time you call bugsnag.Configure. This will prevent bugsnag from being able to notify you about unhandled panics.

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"}, which prevents fields like password, password_confirmation and secret_answer from being sent.

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{"main*"}. 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/.

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

ReleaseStage

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

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

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 (or just panic() instead ;).

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