diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bd74b2a0..c1bfee903 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Fixes + +- ANR events now include the relevant mechanism they have been captured from ([#1955](https://github.com/getsentry/sentry-unity/pull/1955)) + ### Dependencies - Bump Java SDK from v7.19.0 to v7.19.1 ([#1946](https://github.com/getsentry/sentry-unity/pull/1946)) diff --git a/src/Sentry.Unity/Integrations/AnrIntegration.cs b/src/Sentry.Unity/Integrations/AnrIntegration.cs index c65f5c113..844a641c7 100644 --- a/src/Sentry.Unity/Integrations/AnrIntegration.cs +++ b/src/Sentry.Unity/Integrations/AnrIntegration.cs @@ -47,6 +47,8 @@ public void Register(IHub hub, SentryOptions sentryOptions) internal abstract class AnrWatchDog { + public const string Mechanism = "MainThreadWatchdog"; + protected readonly int DetectionTimeoutMs; // Note: we don't sleep for the whole detection timeout or we wouldn't capture if the ANR started later. protected readonly int SleepIntervalMs; @@ -78,7 +80,10 @@ protected void Report() { var message = $"Application not responding for at least {DetectionTimeoutMs} ms."; Logger?.LogInfo("Detected an ANR event: {0}", message); - OnApplicationNotResponding?.Invoke(this, new ApplicationNotRespondingException(message)); + + var exception = new ApplicationNotRespondingException(message); + exception.SetSentryMechanism(Mechanism, "Main thread unresponsive.", false); + OnApplicationNotResponding?.Invoke(this, exception); } } } diff --git a/test/Sentry.Unity.Tests/AnrDetectionTests.cs b/test/Sentry.Unity.Tests/AnrDetectionTests.cs index 000562729..a8aa5c0d3 100644 --- a/test/Sentry.Unity.Tests/AnrDetectionTests.cs +++ b/test/Sentry.Unity.Tests/AnrDetectionTests.cs @@ -6,6 +6,7 @@ using UnityEngine; using UnityEngine.TestTools; using Sentry.Extensibility; +using Sentry.Protocol; using Sentry.Unity.Integrations; using Sentry.Unity.Tests.SharedClasses; @@ -67,6 +68,8 @@ public IEnumerator DetectsStuckUI([ValueSource(nameof(MultiThreadingTestValues)) Assert.IsNotNull(arn); Assert.That(arn!.Message, Does.StartWith("Application not responding ")); + Assert.That(arn!.Data.Contains(Mechanism.MechanismKey)); // Sanity Check + Assert.That(arn!.Data[Mechanism.MechanismKey], Is.EqualTo(AnrWatchDog.Mechanism)); } [UnityTest]