Google App Engine guide

Add Bugsnag to your Google App Engine based Go applications.


Download the code via go get:

go get

Basic configuration

  1. Configure bugsnag at the start of your init() function:

    import ""
    func init() {
            // Your Bugsnag project API key
            APIKey:          "YOUR API KEY HERE",
            // The import paths for the Go packages containing your source files
            ProjectPackages: []string{"main*", ""},
        // ...

    NOTE: Initializing Bugsnag in a location other than the start of your application may have unintended side effects, due to the monitoring behavior of Configuration.PanicHandler, which wraps and monitors the application process. See the configuration documentation for more details.

  2. Wrap every http.Handler or http.HandlerFunc with Bugsnag:

    // a. If you're using HandlerFuncs
    http.HandleFunc("/", bugsnag.HandlerFunc(
        func (w http.ResponseWriter, r *http.Request) {
            // ...
    // b. If you're using Handlers
    http.Handle("/", bugsnag.Handler(myHttpHandler))
  3. In order to use Bugsnag, you must provide the current appengine.Context, or current *http.Request as rawData (This is done automatically for bugsnag.Handler and bugsnag.HandlerFunc). The easiest way to do this is to create a new instance of the notifier.

    c := appengine.NewContext(r)
    notifier := bugsnag.New(c)
    if err != nil {
    go func () {
        defer notifier.Recover()
        // ...

Reporting unhandled panics

After completing installation and basic configuration, unhandled panics will be automatically reported. Error data will begin to appear in your project’s dashboard. To ensure panics from goroutines are handled effectively, see reporting panics from goroutines.

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

Reporting handled errors

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

if err != nil {

When reporting handled errors, 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.

Reporting panics from goroutines

Since goroutines are generally non-blocking, panics captured on a goroutine may crash the application before having the opportunity to be delivered to Bugsnag unless intentionally handled.

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.

go func() {
    defer bugsnag.AutoNotify()

    // ...

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()

    // ...

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.

        "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.User{Id: "1234", Name: "Conrad", Email: ""})

For more information, see the reporting handled errors reference.

Session tracking

Bugsnag can track the number of “sessions” that happen in your application. This enables Bugsnag to provide and compare crash rates between releases to help you understand the quality of your releases.

Session tracking is coming soon to this platform.

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