From 48f6ac7e2167d205c203319f0bfb2774dff92885 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Wed, 29 Oct 2025 15:59:51 +0100 Subject: [PATCH 1/4] Set the correct mechanism for exceptions captured by the logging integrations --- src/Sentry.Unity/Integrations/UnityErrorLogException.cs | 6 ++++-- src/Sentry.Unity/Integrations/UnityLogHandlerIntegration.cs | 3 +-- src/sentry-dotnet | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Sentry.Unity/Integrations/UnityErrorLogException.cs b/src/Sentry.Unity/Integrations/UnityErrorLogException.cs index 8d7a6daeb..5cd96b4bb 100644 --- a/src/Sentry.Unity/Integrations/UnityErrorLogException.cs +++ b/src/Sentry.Unity/Integrations/UnityErrorLogException.cs @@ -23,7 +23,7 @@ internal class UnityErrorLogException : Exception private readonly SentryOptions? _options; private readonly IDiagnosticLogger? _logger; - public UnityErrorLogException(string logString, string logStackTrace, SentryOptions? options) + public UnityErrorLogException(string logString, string logStackTrace, SentryOptions? options) : base(logString) { _logString = logString; _logStackTrace = logStackTrace; @@ -54,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 b93b15a1a..0af9b025e 100644 --- a/src/Sentry.Unity/Integrations/UnityLogHandlerIntegration.cs +++ b/src/Sentry.Unity/Integrations/UnityLogHandlerIntegration.cs @@ -72,8 +72,7 @@ internal void CaptureException(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); } diff --git a/src/sentry-dotnet b/src/sentry-dotnet index 85615664d..5a11ac58c 160000 --- a/src/sentry-dotnet +++ b/src/sentry-dotnet @@ -1 +1 @@ -Subproject commit 85615664d4060ad475e316911bd79d364b50567a +Subproject commit 5a11ac58c2904c2c8466f6b37e44a4f8c93fafc6 From c37075caa99609f8f18ab7c19aa010af4a695979 Mon Sep 17 00:00:00 2001 From: Sentry Github Bot Date: Wed, 29 Oct 2025 15:40:20 +0000 Subject: [PATCH 2/4] Format code --- src/Sentry.Unity/Integrations/UnityErrorLogException.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sentry.Unity/Integrations/UnityErrorLogException.cs b/src/Sentry.Unity/Integrations/UnityErrorLogException.cs index 5cd96b4bb..9b163f632 100644 --- a/src/Sentry.Unity/Integrations/UnityErrorLogException.cs +++ b/src/Sentry.Unity/Integrations/UnityErrorLogException.cs @@ -56,7 +56,7 @@ public SentryException ToSentryException() Handled = true, Type = "unity.log", Synthetic = true, - Data = { {Mechanism.TerminalKey, false} } + Data = { { Mechanism.TerminalKey, false } } } }; } From 8ed60556cb4bc0ccac5ec18661e22ac3a9d8a737 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Wed, 29 Oct 2025 16:59:29 +0100 Subject: [PATCH 3/4] Updated tests --- test/Sentry.Unity.Tests/UnityErrorLogExceptionTests.cs | 8 ++++++-- .../Sentry.Unity.Tests/UnityLogHandlerIntegrationTests.cs | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) 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 9070daa95..009a430f1 100644 --- a/test/Sentry.Unity.Tests/UnityLogHandlerIntegrationTests.cs +++ b/test/Sentry.Unity.Tests/UnityLogHandlerIntegrationTests.cs @@ -58,6 +58,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] From edb0ee7c89071a9d1809c73395ba4ec8570daadb Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Wed, 29 Oct 2025 17:06:28 +0100 Subject: [PATCH 4/4] Updated CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 047904e22..c3504bca0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - `sentry-native` is now built on Ubuntu 22.04 instead of Ubuntu 20.04, which reached EOL in May 2025. If you are running you game on a server on Ubuntu 20.04, you should update the OS before upgrading to this SDK version. ([#2355](https://github.com/getsentry/sentry-unity/pull/2355)) +### 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)) + ### Dependencies - Bump CLI from v2.56.0 to v2.56.1 ([#2356](https://github.com/getsentry/sentry-unity/pull/2356))