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.
Key terms:
- An event is one instance of sending data to Sentry. Generally, this data is an error or exception.
- An issue is a grouping of similar events.
- The reporting of an event is called capturing. When an event is captured, it's sent to Sentry.
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
.
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:
// 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.
SentrySdk.CaptureMessage("Something went wrong");
By default, the SDK only provides a stack trace for captured exceptions. To provide a stack trace in message events, captured either through SentrySdk.CaptureMessage
or Debug.LogError
, you need to set AttachStacktrace
to true
in the Logging
tab in the editor (Tools->Sentry).
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").