Customizing error reports

In order to quickly reproduce and fix errors, it is often helpful to send additional application-specific diagnostic data to BugSnag.

This documentation is for version 5 of the BugSnag Unity notifier. We recommend upgrading to the latest release using our Upgrade guide. Documentation for the current release can be found here.

Adding callbacks

Custom call back functions (middleware) can be configured to run just before an error report is sent. These callbacks have full access to the error report and can modify it before it’s sent. They also have the opportunity to prevent the error report from being sent all together. The middleware signature takes an error report and does not return anything.

The Report object

The report object is a dictionary of the payload which will be serialized and sent to BugSnag. The following convenience methods/properties exist on the object to allow you to manipulate and/or perform logic on in any middleware that you wish to write.

App

Application specific information.

Bugsnag.BeforeNotify(report => {
  report.App.Remove("version");
});

The list of breadrcumbs leading up to the current error.

Bugsnag.BeforeNotify(report => {
  foreach (var breadcrumb in report.Breadcrumbs)
  {
    breadcrumb["name"] = "[Filtered]";
  }

Context

Set the context of the error report. This is notionally the location of the error. Context is displayed in the dashboard prominently.

Bugsnag.BeforeNotify(report => {
  report.Context = "billing";
});

Device

Information on the device where the error occurred. This object is a dictionary with some preset keys that can be manipulated.

Bugsnag.BeforeNotify(report => {
  report.Device.Remove("hostname");
});

Exceptions

Each exception that makes up the error that occurred. Inner exceptions, AggregateExceptions and ReflectionTypeLoadExceptions are all unwound and included in this list.

Each Exception is a dictionary including a stacktrace property, which is an array of dictionaries containing file, lineNumber, and method.

Bugsnag.BeforeNotify(report => {
  foreach (var exception in report.Exceptions)
  {
    exception.Remove("message");
  }

GroupingHash

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.

Bugsnag.BeforeNotify(report => {
  report.GroupingHash = "custom-hash";
});

Ignore()

Calling Ignore() on a report object will cause the report to not be sent to BugSnag. This means that you can choose dynamically not to send an error depending on application state or the error itself.

Bugsnag.BeforeNotify(report => {
  report.Ignore();
});

IsHandled

Gets the handled status of this event. If the event is being sent due to being called with Notify then this will true, otherwise if it sent due to an unhandled exception handler then this will be false.

Bugsnag.BeforeNotify(report => {
  if (report.IsHandled)
  {
    // perform some action
  }
});

Metadata

Provides access to the metadata in the error report. You can also add your own additional metadata using this property.

Bugsnag.BeforeNotify(report => {
  // add a new tab into the dashboard with 'account' as the name
  report.Metadata.Add("account", new Dictionary<string, object> { { "paying", true } });
});

Severity

Set the severity of the error. Severity can be error, warning or info.

Bugsnag.BeforeNotify(report => {
  report.Severity = Bugsnag.Severity.Info;
});

User

Set information about the user the error occurred for.

Bugsnag.BeforeNotify(report=> {
  report.Metadata.Add("user", new Dictionary<string, string>()
  {
    { "Id", "1" },
    { "Name", "Testy McTest" },
    { "Email", "support@bugsnag.com" } 
  });
});