Skip to content

Commit 70a7c7f

Browse files
authored
feat: Mark exceptions as NonTerminal (#2376)
1 parent 2ccdfa9 commit 70a7c7f

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
### Features
1010

11+
- 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))
1112
- 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))
1213

1314
### Dependencies

src/Sentry.Unity/Integrations/UnityErrorLogException.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ internal class UnityErrorLogException : Exception
2323
private readonly SentryOptions? _options;
2424
private readonly IDiagnosticLogger? _logger;
2525

26-
public UnityErrorLogException(string logString, string logStackTrace, SentryOptions? options)
27-
: base(logString)
26+
public UnityErrorLogException(string logString, string logStackTrace, SentryOptions? options) : base(logString)
2827
{
2928
_logString = logString;
3029
_logStackTrace = logStackTrace;
@@ -55,7 +54,9 @@ public SentryException ToSentryException()
5554
Mechanism = new Mechanism
5655
{
5756
Handled = true,
58-
Type = "unity.log"
57+
Type = "unity.log",
58+
Synthetic = true,
59+
Data = { { Mechanism.TerminalKey, false } }
5960
}
6061
};
6162
}

src/Sentry.Unity/Integrations/UnityLogHandlerIntegration.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ internal void ProcessException(Exception exception, UnityEngine.Object? context)
7777
// NOTE: This might not be entirely true, as a user could as well call `Debug.LogException`
7878
// and expect a handled exception but it is not possible for us to differentiate
7979
// https://docs.sentry.io/platforms/unity/troubleshooting/#unhandled-exceptions---debuglogexception
80-
exception.Data[Mechanism.HandledKey] = false;
81-
exception.Data[Mechanism.MechanismKey] = "Unity.LogException";
80+
exception.SetSentryMechanism("Unity.LogException", handled: false, terminal: false);
8281
_ = _hub.CaptureException(exception);
8382

8483
if (_options.Experimental.CaptureStructuredLogsForLogType.TryGetValue(LogType.Exception, out var captureException) && captureException)

test/Sentry.Unity.Tests/UnityErrorLogExceptionTests.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ public void ToSentryException_ParsingTestCases(
9393
Mechanism = new Mechanism
9494
{
9595
Handled = true,
96-
Type = "unity.log"
96+
Type = "unity.log",
97+
Synthetic = true,
98+
Data = { {Mechanism.TerminalKey, false} }
9799
}
98100
}
99101
},
@@ -189,7 +191,9 @@ public void ToSentryException_ParsingTestCases(
189191
Mechanism = new Mechanism
190192
{
191193
Handled = true,
192-
Type = "unity.log"
194+
Type = "unity.log",
195+
Synthetic = true,
196+
Data = { {Mechanism.TerminalKey, false} }
193197
}
194198
}
195199
}

test/Sentry.Unity.Tests/UnityLogHandlerIntegrationTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ public void CaptureException_ExceptionCapturedAndMechanismSet()
6363

6464
Assert.IsTrue(capturedEvent.Exception!.Data.Contains(Mechanism.MechanismKey));
6565
Assert.AreEqual("Unity.LogException", (string)capturedEvent.Exception!.Data[Mechanism.MechanismKey]);
66+
67+
Assert.IsTrue(capturedEvent.Exception!.Data.Contains(Mechanism.TerminalKey));
68+
Assert.IsFalse((bool)capturedEvent.Exception!.Data[Mechanism.TerminalKey]);
6669
}
6770

6871
[Test]

0 commit comments

Comments
 (0)