Usage

Use the SDK to manually capture errors and other events.

Sentry's SDK hooks into the game engine and automatically reports errors, uncaught exceptions, as well as other types of errors depending on the platform.

By default, the Sentry Unity SDK automatically captures errors through Unity's logging system. For details on this see the Automatic Error Capture documentation.

In addition to automatic capture, you can manually capture errors, exceptions, and messages as described below.

The most common form of capturing is to capture errors. In Unity C# code, you can use SentrySdk.CaptureException(exception) to explicitly report exceptions and mark them as handled.

Copied
try
{
    AFunctionThatMightFail();
}
catch (Exception e)
{
    SentrySdk.CaptureException(e);
}

While capturing an event, these get also recorded as breadcrumbs that lead up to the next event. Breadcrumbs are different from events: they will not create an event in Sentry, but will be buffered until the next event is sent. Learn more about breadcrumbs in our Breadcrumbs documentation.

You can ignore exceptions by their type when initializing the SDK:

Copied
// Add this to the SDK initialization callback
options.AddExceptionFilterForType<OperationCanceledException>();

This modifies the behavior of the entire inheritance chain. As a result, the example code will also filter out TaskCanceledException since it derives from OperationCanceledException.

Another common operation is to capture a bare message. A message is textual information that should be sent to Sentry. The SDK will automatically capture messages created through Debug.LogError(). You can opt-out of this behaviour on the Logging tab in the editor (Tools->Sentry).

Messages show up as issues on your issue stream, with the message as the issue name.

Copied
SentrySdk.CaptureMessage("Something went wrong");
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").