Customizing error reports

The OnBeforeNotify configuration option allows for modifying reported information by editing fields on bugsnag.Event.

Modifying report information

Any value on an event can be overridden prior to delivery:

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

    // Change the context of an event
    event.Context = "GET /api/cart@handler"
    return nil
})

Or removed altogether:

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

    // Remove a potentially sensitive parameter from the raw payload data
    delete(event.MetaData["params"], "credit_card_param")
    return nil
})

Skipping lines in a stacktrace

If you have your own logging wrapper all of your errors will appear to originate from inside it. You can avoid this problem by constructing an error with a stacktrace manually, and then passing that to Bugsnag.notify:

import (
    "github.com/bugsnag/bugsnag-go"
    "github.com/bugsnag/bugsnag-go/errors"
)

func LogError(e error) {
    // 1 removes one line of stacktrace, so the caller of LogError
    // will be at the top.
    e = errors.New(e, 1)
    bugsnag.Notify(e)
}

The bugsnag.Event object

Context

A short description of the error location, such as the URL path or top filename from the stack trace.

Error

The original error which caused the event.

ErrorClass

The name or title of the report sent to Bugsnag

GroupingHash

A hint for how a report should be grouped with other events in a project. All reports with the same grouping hash will be grouped together.

Message

The description or summary of the report sent to Bugsnag

MetaData

Additional information appended to the report, organized as key/value pairs in named sections.

RawData

The raw information available about the event. This structure is not appended to the report directly but is available to cache request information or additional context.

Stacktrace

An array of stack frames leading to the original error.

User

Information about the user who encountered the event