Customizing error reports

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

Before-notify callbacks

If you’d like to add diagnostic data to every error report, or adjust error reports conditionally, you can set a callback which will be run before each error report is sent:

Bugsnag::setBeforeNotifyFunction(function ($report) {
    // For example, add customer information to every error report
        'account' => [
            'name' => 'Acme Co.',
            'paying_customer' => true

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.

You can also return false from your callback to stop this error report being delivered.

The $error object

The following properties and methods are available on the $error object.


Set the error name sent in the error report



Set the error message sent in the error report

$error->setMessage('This was a mistake.');


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

By default, all unhandled exceptions are set to severity error and all handled exceptions are set to severity warning.



Sets the grouping hash of the error report. All errors with the same grouping hash are grouped together. This is an advanced usage of the library and mis-using it will cause your errors not to group properly in your dashboard.

$error->setGroupingHash($exception->message . $exception->class);


Set additional metadata to send with this error report, or filter existing metadata.

    'account' => array(
        'paying' => true,
        'name' => 'Acme Co'

You can also pass a 2nd paramater of false stop us merging your metadata, and force us to completely replace it.


You can set the associated user on the error.

    'id' => '123456',
    'name' => 'Leeroy Jenkins',
    'email' => '',


Inspect or modify the stacktrace of the error report.

For example, if BugSnag is called by a wrapper library, you can remove stack frames from the stacktrace:

function before_bugsnag_notify($error) {
    // Extract the first frame of the stacktrace
    $firstFrame = $error->stacktrace->frames[0];

    // Check if the first frame is in a particular file
    if ($firstFrame && $firstFrame['file'] === 'My_Logger.php') {
        // Remove the first frame from the stacktrace
        array_splice($error->stacktrace->frames, 0, 1);