Customizing breadcrumbs

In order to understand what happened in your application before each error, it can be helpful to leave short log statements that we call breadcrumbs. A configurable number of breadcrumbs are attached to each error report to help diagnose what events led to the error.

Automatic breadcrumbs

By default, BugSnag captures breadcrumbs for common actions and device changes, including:

  • Low memory warnings
  • Device rotation
  • Menu presentation
  • Screenshot capture (not the screenshot itself)
  • Undo and redo
  • Table view selection
  • Window visibility changes
  • Non-fatal errors
  • Log messages

This can be controlled using the Enabled Breadcrumb Types configuration option.

Adding manual breadcrumbs

Append manual breadcrumbs with a message via the UBugsnagFunctionLibrary:

UBugsnagFunctionLibrary::LeaveBreadcrumb(TEXT("App loaded"));
UBugsnagFunctionLibrary::LeaveBreadcrumb(TEXT("User clicked a button"));

BugSnag will keep track of the time and order of the breadcrumbs, and show them on your dashboard.

You can also leave breadcrumbs from Blueprints using BugSnag’s “Leave Breadcrumb” action.

Attaching metadata

Additional data can be attached to breadcrumbs by providing the additional Metadata argument. Metadata will be presented on the BugSnag dashboard alongside the breadcrumb name and type:

TSharedRef<FJsonObject> Metadata = MakeShared<FJsonObject>();
Metadata->SetStringField(TEXT("from"), TEXT("moka"));
Metadata->SetStringField(TEXT("to"), TEXT("french press"));

UBugsnagFunctionLibrary::LeaveBreadcrumb(TEXT("Preference updated"), Metadata,
    EBugsnagBreadcrumbType::State);

Breadcrumb “types” can be used to differentiate different types of events, such as user activity and changes in application state. See the Enabled Breadcrumb Types configuration option for a description of the types available. This type will affect how your breadcrumb is shown on the dashboard but they will not be affected by the Enabled Breadcrumb Types configuration option.

Discarding and amending breadcrumbs

You can register a callback that is executed each time a breadcrumb is captured using an On Breadcrumb callback as part of your initial BugSnag configuration. This can be helpful if you wish to filter out certain automatic breadcrumbs from your application or amend the data contained within them.

Configuration->AddOnBreadcrumb([](TSharedRef<IBugsnagBreadcrumb> Breadcrumb)
{
    if (Breadcrumb->GetMessage() == TEXT("Noisy breadcrumb"))
    {
        return false; // ignore the breadcrumb
    }
    else
    {
        return true; // capture the breadcrumb
    }
});

Adding callbacks

We recommend adding callbacks through BugSnag’s initial configuration (AddOnBreadcrumb) to ensure that it is registered as soon as BugSnag starts. However, the following method is provided to allow callbacks to be added whilst the application is running:

UBugsnagFunctionLibrary::AddOnBreadcrumb([](TSharedRef<IBugsnagBreadcrumb> Breadcrumb)
{
    return true;
});

The IBugsnagBreadcrumb class

The following information is available on the IBugsnagBreadcrumb class, the representation of breadcrumb information passed to a breadcrumb callback.

property type description
Message String The description of the breadcrumb
Metadata JsonObject Diagnostic data relating to the breadcrumb
Timestamp DateTime The timestamp that the breadcrumb was left
Type BreadcrumbType The type of breadcrumb left