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

Overriding Bugsnag’s grouping algorithm

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

Creating multiple clients

Separate clients can be created to report handled errors with independent configuration options.

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

client.Notify(err)

Any place that lets you pass in rawData also supports custom configuration. For example, to send an individual error to a different project:

bugsnag.Notify(err, bugsnag.Configuration{APIKey: "YOUR_OTHER_API_KEY"})

The bugsnag.Event object

Context

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

Note: This is not a context.Context. See bugsnag-context for more details.

event.Context = "billing"

Error

The original error which caused the event.

ErrorClass

The name or title of the report sent to Bugsnag

event.ErrorClass = "failed retry"

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.

// group events by error class and file
event.GroupingHash = fmt.Sprintf("%s:%s", event.Stacktrace[0].File, event.ErrorClass)

Message

The description or summary of the report sent to Bugsnag

event.Message = "Invalid credential format"

MetaData

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

event.MetaData.Add("job", "id", job.Id)

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.

for _, datum := range event.RawData {
    if user, ok := datum.(*MyUserInfo); ok {
        event.User = &User{Id: user.Id}
    }
}

Stacktrace

An array of stack frames leading to the original error.

// trim logger from stack trace
if event.Stacktrace[0].File == "mylogger.go" {
    event.Stacktrace = event.Stacktrace[1:]
}

Unhandled

If the event was automatically detected and should be counted against the project’s stability score.

event.Unhandled = true

User

event.User = &User{Id: myUser.Id, Email: myUser.EmailAddress}

Information about the user who encountered the event

Request

Information about the HTTP request for which the event occurred

if event.Request.URL == "/dev-check" {
    // ignore or modify events from a particular endpoint
}