diff --git a/CHANGELOG.md b/CHANGELOG.md index a89e9fdcd..7966f5284 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Features +- The SDK no longer ends sessions as crashed when capturing unhandled or logged exceptions. Instead, sessions get correctly marked as `SessionEndStatus.Unhandled` ([#2376](https://github.com/getsentry/sentry-unity/pull/2376)) - Added support for Structured Logging. The `SentrySdk.Logger` API is now exposed for Unity users, enabling structured log capture. The SDK can also automatically capture and send Debug logs based on the options configured. ([#2368](https://github.com/getsentry/sentry-unity/pull/2368)) ### Dependencies diff --git a/src/Sentry.Unity/Integrations/UnityErrorLogException.cs b/src/Sentry.Unity/Integrations/UnityErrorLogException.cs index c1dcf6237..9b163f632 100644 --- a/src/Sentry.Unity/Integrations/UnityErrorLogException.cs +++ b/src/Sentry.Unity/Integrations/UnityErrorLogException.cs @@ -23,8 +23,7 @@ internal class UnityErrorLogException : Exception private readonly SentryOptions? _options; private readonly IDiagnosticLogger? _logger; - public UnityErrorLogException(string logString, string logStackTrace, SentryOptions? options) - : base(logString) + public UnityErrorLogException(string logString, string logStackTrace, SentryOptions? options) : base(logString) { _logString = logString; _logStackTrace = logStackTrace; @@ -55,7 +54,9 @@ public SentryException ToSentryException() Mechanism = new Mechanism { Handled = true, - Type = "unity.log" + Type = "unity.log", + Synthetic = true, + Data = { { Mechanism.TerminalKey, false } } } }; } diff --git a/src/Sentry.Unity/Integrations/UnityLogHandlerIntegration.cs b/src/Sentry.Unity/Integrations/UnityLogHandlerIntegration.cs index d869a4ceb..4318f3474 100644 --- a/src/Sentry.Unity/Integrations/UnityLogHandlerIntegration.cs +++ b/src/Sentry.Unity/Integrations/UnityLogHandlerIntegration.cs @@ -77,8 +77,7 @@ internal void ProcessException(Exception exception, UnityEngine.Object? context) // NOTE: This might not be entirely true, as a user could as well call `Debug.LogException` // and expect a handled exception but it is not possible for us to differentiate // https://docs.sentry.io/platforms/unity/troubleshooting/#unhandled-exceptions---debuglogexception - exception.Data[Mechanism.HandledKey] = false; - exception.Data[Mechanism.MechanismKey] = "Unity.LogException"; + exception.SetSentryMechanism("Unity.LogException", handled: false, terminal: false); _ = _hub.CaptureException(exception); if (_options.Experimental.CaptureStructuredLogsForLogType.TryGetValue(LogType.Exception, out var captureException) && captureException) diff --git a/test/Sentry.Unity.Tests/UnityErrorLogExceptionTests.cs b/test/Sentry.Unity.Tests/UnityErrorLogExceptionTests.cs index 0ce5990d7..f49c237b4 100644 --- a/test/Sentry.Unity.Tests/UnityErrorLogExceptionTests.cs +++ b/test/Sentry.Unity.Tests/UnityErrorLogExceptionTests.cs @@ -93,7 +93,9 @@ public void ToSentryException_ParsingTestCases( Mechanism = new Mechanism { Handled = true, - Type = "unity.log" + Type = "unity.log", + Synthetic = true, + Data = { {Mechanism.TerminalKey, false} } } } }, @@ -189,7 +191,9 @@ public void ToSentryException_ParsingTestCases( Mechanism = new Mechanism { Handled = true, - Type = "unity.log" + Type = "unity.log", + Synthetic = true, + Data = { {Mechanism.TerminalKey, false} } } } } diff --git a/test/Sentry.Unity.Tests/UnityLogHandlerIntegrationTests.cs b/test/Sentry.Unity.Tests/UnityLogHandlerIntegrationTests.cs index 7edff354c..750cb8bd1 100644 --- a/test/Sentry.Unity.Tests/UnityLogHandlerIntegrationTests.cs +++ b/test/Sentry.Unity.Tests/UnityLogHandlerIntegrationTests.cs @@ -63,6 +63,9 @@ public void CaptureException_ExceptionCapturedAndMechanismSet() Assert.IsTrue(capturedEvent.Exception!.Data.Contains(Mechanism.MechanismKey)); Assert.AreEqual("Unity.LogException", (string)capturedEvent.Exception!.Data[Mechanism.MechanismKey]); + + Assert.IsTrue(capturedEvent.Exception!.Data.Contains(Mechanism.TerminalKey)); + Assert.IsFalse((bool)capturedEvent.Exception!.Data[Mechanism.TerminalKey]); } [Test]