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.

setName

Set the error name sent in the error report

$error->setName('OopsError');

setMessage

Set the error message sent in the error report

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

setSeverity

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.

$error->setSeverity('info');

setGroupingHash

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

setMetaData

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

setUser

stacktrace

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:

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