Skip to content

Commit

Permalink
reworked the error capture explainer
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsandfoxes committed Mar 4, 2025
1 parent cc4b9d2 commit 20d6ed2
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions docs/platforms/unity/configuration/error-capture.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ The Unity SDK relies on two integrations to capture errors: `UnityLogHandlerInte

## UnityLogHandlerIntegration

The SDK uses the `UnityLogHandlerIntegration` to hook into Unity's logging system. From there it receives all log messages that are logged via the `Debug.Log`, `Debug.LogWarning`, and `Debug.LogError` methods. These log messages are also added as breadcrumbs to future events. By default, the SDK will automatically capture messages logged via `Debug.LogError` as error events. This can be disabled by unchecking the automatic capture of `Debug.LogError` on the `Enrichment` tab, or by setting the `CaptureLogErrorEvents` option to `false`.
The SDK uses the `UnityLogHandlerIntegration` to hook into Unity's logging system. From there it receives all log messages that are logged via the `Debug.Log`, `Debug.LogWarning`, and `Debug.LogError` methods and those log messages are added as breadcrumbs to future events. By default, the SDK will also automatically capture messages logged via `Debug.LogError` as error events and send them to Sentry. This behaviour can be disabled by unchecking the automatic capture of `Debug.LogError` on the `Enrichment` tab, or programmatically, by setting the `CaptureLogErrorEvents` option to `false` in the [configure callback](/platforms/unity/configuration/options/programmatic-configuration).

https://docs.unity3d.com/6000.0/Documentation/Manual/stack-trace.html
### Stacktrace Support & Line Numbers

If configured, the SDK receives the stacktrace as part of the logging messages in a raw string format. The SDK is able to parse this format and display it in the Sentry UI. Unfortunately, to provide line numbers, the SDK needs to have an actual thrown exception object to fetch the required information for symbolication. Read more about the IL2CPP error symbolication works [here](/platforms/unity/configuration/il2cpp). If you're using Unity 6 or newer, you can enable the source code line numbers in the [player settings](https://docs.unity3d.com/6000.0/Documentation/Manual/il2cpp-managed-stack-traces.html). These line numbers are then part of the stringified stacktrace and will be parsed by the SDK.
If [configured](https://docs.unity3d.com/6000.0/Documentation/Manual/stack-trace.html), Unity will include the stacktraces with the log messages as raw strings. The SDK is able to parse and display this stacktrace in the issues details.

If you're using Unity 6 or newer, you have the option to to enable the source code line numbers in the [player settings](https://docs.unity3d.com/6000.0/Documentation/Manual/il2cpp-managed-stack-traces.html). These line numbers are then part of the stringified stacktrace and will be parsed by the SDK. Unfortunately, since there is no native exception at the time of logging, the SDK is not be able to provide line numbers.

<Note>
If you're using a version older than Unity 6, the SDK is unable to provide line numbers for events captured through `Debug.LogError`. Line numbers are not part of the logging information provided by Unity.
</Note>

## UnityApplicationLoggingIntegration

The SDK uses the `UnityApplicationLoggingIntegration` to add its own log handler right before Unity's logging system and passes the logs back to Unity. This allows the SDK to capture errors from the `Application.logMessageReceived` method. All handled exceptions (such as those captured via `Log.LogException` calls) and unhandled exceptions are captured by the SDK. These messages contain the actual exception object, which allows the SDK to fetch the required information for symbolication.
The SDK uses the `UnityApplicationLoggingIntegration` to add its own log handler right before Unity's logging system. It then passes the logs back to Unity. This allows the SDK to capture errors through the `Application.logMessageReceived` method. All handled exceptions - such as those captured via `Log.LogException` calls - and unhandled exceptions end up on that call and are captured by the SDK. These messages contain the actual exception object. This allows the SDK to call into the IL2CPP backend and connect this managed exception to the native exception, allowing for server side symbolication. You can read more about the IL2CPP error integration works [here](/platforms/unity/configuration/il2cpp).

0 comments on commit 20d6ed2

Please sign in to comment.