Customizing error reports

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

Adding callbacks

Custom call back functions can be configured to run just before an error event is sent. These callbacks have full access to the error and can modify it before its sent. They also have the opportunity to prevent the error from being sent all together. A callback should take an error Event object as a parameter and return a boolean indicating if the event should be notified (Func<Event,bool>);

Note that these callbacks will not be called if the exception class is an class being ignored via SetIgnoreClasses() or the current release stage is one that has been configured not to be notified on via SetNotifyReleaseStages().

bugsnag.Config.BeforeNotify(error =>
{
    // Sets the groupingHash option
    error.setGroupingHash("My Group");

    // Elevate all warnings as errors
    if (error.Severity == Severity.Warning)
    {
        error.Severity = Severity.Error;
        error.addToTab("Reporting", "Elevated", true);
    }

    // Ignore all exceptions marked as minor
    var isMinor = error.Exception.Message.Contains("[MINOR]");
    return !isMinor;
});

The Error event object

When an exception occurs, the details of the exception is collated and recorded into an error Event object. This object stores all the information about the exception that will be sent to Bugsnag. By setting this object properties, you can send additional information or modify an existing object before its sent.

All event objects can be modified just before they are sent to Bugsnag using the BeforeNotify callback

The available properties available

Exception (Read Only)

The exception the event is representing. This needs to be provided when creating an error event and can not be modified.

Exception exp = error.Exception;

IsRuntimeEnding (Read Only)

If an exception occurs that has resulted in the application crashing out (runtime ended), this flag will be true.

bool hasCrashed = error.IsRuntimeEnding;

GroupingHash

Sets the grouping hash used by Bugsnag.com to manually override the default grouping technique. This option is not recommended, and should only be manually set with care.

Any errors that are sent to Bugsnag, that have the same grouping hash will be grouped as one.

error.GroupingHash = "d41d8cd98f00b204e9800998ecf8427e";

Severity

The severity can be set directly on the event. Valid severities are Severity.Error, Severity.Warning and Severity.Info.

error.Severity = Severity.Info;

Metadata

Additional information that you want to include with an error event is done using the Metadata property. The metadata represents tabs and tab entries that can be visualized from the Bugsnag dashboard. Each tab entry consists of a entry key and an entry value. The entry key is string, but the entry value can be any object that can serialized in JSON e.g. dictionaries, arrays, complex objects etc.

Each event object will start with a blank metadata object ready to be added to. However you can create your own metadata object and set the property directly. The metadata object has methods to help you add your own data.

AddToTab

This is the main way to add data to a Metadata object. Specify the tab, tab entry key and tab entry value you want to add. If the entry key already exists in the tab your trying to add to, the value will be overwritten with the new value. If no tab is specified, the data will be added to the “Custom Data” tab.

// Adds company details under the "Company Details" tab
error.Metadata.AddToTab("Company Details", "Name", "My Company");
error.Metadata.AddToTab("Company Details", "Phone", "01123456789012");
error.Metadata.AddToTab("Company Details", "Email", "admin@mycompany.com");

// Adds a list of developers under a single entry
var devs = new string[]{"Bob Adams", "James Richards", "Lucy Patrick"};
error.Metadata.AddToTab("Team", "Developers", devs);

// Adds some app data to the custom data tab
error.Metadata.AddToTab("Full Test Suite", true);

RemoveTab

Removes a tab that exists in the metadata.

// Removes the Dev Only tab
error.Metadata.RemoveTab("Dev Only");

RemoveTabEntry

Removes a tab entry that exists in the metadata.

// Removes the unit test result entry
error.Metadata.RemoveTabEntry("Build Results", "Test Results");