Customizing error reports

Add diagnostic data to every error report, or conditionally adjust error reports.

Adding callbacks

If you’d like to add diagnostic data to reports, or adjust error reports conditionally, you can use a before notify callback, which will be run immediately after an error is captured or reported:

Bugsnag.beforeNotify {
    it.addToTab("account", "name", "Acme Co.")
    it.addToTab("account", "paying_customer", true)

    // Return `false` if you'd like to stop this error being reported

The callback gives you access to the error object, so you can inspect and modify the error report which is about to be sent to Bugsnag.

Note: callbacks do not run when capturing NDK crashes, as the system terminates immediately. To include additional information in native crash reports, see Customizing native crash reports.

Customizing native crash reports

Use BeforeSend callbacks to modify or cancel native error reports immediately prior to report delivery.

val config = Configuration("your-api-key-here")
config.beforeSend {
    // Attach customer information to every error report
    val error = it.error
    error.addToTab("account", "name", "Acme Co.")
    error.addToTab("account", "paying_customer", true)

    // Return `false` if you'd like to stop this error being reported
Bugsnag.init(this, config)

Note: Native crash reports are not delivered until next time the app is launched, which may be hours or days later and perhaps in a different version of the app altogether. Avoid attaching additional information to a report that does not relate to the crashed session.

Disabling error reporting

If you wish to disable error reporting, you can return false within config.beforeSend. This would allow for users to opt out of sending error reports, for example:

val config = Configuration("your-api-key-here")
config.beforeSend { false } // no error report will be sent
Bugsnag.init(this, config)

The error object

The following properties and methods are available on the Error object, the representation of error information available in before notify callbacks.


Sets a piece of information to be displayed in the error page. The first argument is the tab name, the second argument is the key for the data, and the third argument is used as the value.

error.addToTab("user", "role", "Administrator")


Returns the context of the error. The context is a summary what what was occurring in the application at the time of the crash, if available, such as the visible activity.


Returns the thrown Throwable.


Returns the full name of the Throwable.


Returns the attached exception metadata, which can be modified to add or remove fields.

val metadata = error.metaData


Returns the Throwable’s array of StackTraceElements.


Returns the User that has been associated with the Error report.


Sets the context of the error. The context is a summary what what was occurring in the application at the time of the crash, if available, such as the visible activity.

error.context = "Pause menu"


Sets the groupingHash used by to manually override the default grouping technique. This option is not recommended, and should be used carefully when used.

Any errors that are sent to Bugsnag, that have the same groupingHash will be grouped as one. As the name implies, this option accepts a hash of sorts.

// ... generate the hash
val groupingHash = "f8803769f3e293dfcabdb6dec5100b8c52c6ae6b"


Overrides the severity of the error. Valid severities are error, warning and info.

error.severity = Severity.WARNING


Sets the user associated with the error report.

error.setUser("123", "", "Bob Johnson")

Modifying the stack trace

It is possible to modify the stack trace that is associated with the error report in the following way:

Create a recursive function which loops copies each stack trace element and sets it back to the Throwable object. Any modifications to the stack trace can be done within this loop

private fun alterStacktrace(t: Throwable) {
    val trace = t.stackTrace

    val newTrace = {
        // YOUR CODE HERE

    t.stackTrace = newTrace.toTypedArray()
    t.cause?.let { alterStacktrace(it) }

Then call this new function from the BeforeNotify function


The report object

The following methods are available on the Report object, the representation of a report on the Bugsnag dashboard in before send callbacks


The Error object associated with this report

report.error.addToTab("user", "role", "Administrator")


Override the API key which is used to deliver the report.

report.apiKey = "my-other-api-key"

Reporting StrictMode violations

If you have enabled StrictMode in your development builds with the penaltyDeath option, then Bugsnag will automatically detect StrictMode exceptions. Any reports for these errors will contain a human readable description of the policy violation (e.g. ActivityLeak) in their metadata.

If you have not already setup StrictMode, you can do so by entering the following code in your Application class. It is strongly recommended that you only enable StrictMode for non-release builds.

if (BuildConfig.DEBUG) {