From a2bf44fa69ec916a8bbe02bbbc986db05a1cf617 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Thu, 9 Jan 2025 16:54:22 +0100 Subject: [PATCH 1/5] added mechanism to anr exception --- src/Sentry.Unity/Integrations/AnrIntegration.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Sentry.Unity/Integrations/AnrIntegration.cs b/src/Sentry.Unity/Integrations/AnrIntegration.cs index c65f5c113..bb9ad0601 100644 --- a/src/Sentry.Unity/Integrations/AnrIntegration.cs +++ b/src/Sentry.Unity/Integrations/AnrIntegration.cs @@ -78,7 +78,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("ANR", handled: false); + OnApplicationNotResponding?.Invoke(this, exception); } } } From b672705c0b972c99283eeca9f24e4ea554536ec8 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Thu, 9 Jan 2025 21:49:20 +0100 Subject: [PATCH 2/5] rename and description --- src/Sentry.Unity/Integrations/AnrIntegration.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sentry.Unity/Integrations/AnrIntegration.cs b/src/Sentry.Unity/Integrations/AnrIntegration.cs index bb9ad0601..a24bb43c3 100644 --- a/src/Sentry.Unity/Integrations/AnrIntegration.cs +++ b/src/Sentry.Unity/Integrations/AnrIntegration.cs @@ -80,7 +80,7 @@ protected void Report() Logger?.LogInfo("Detected an ANR event: {0}", message); var exception = new ApplicationNotRespondingException(message); - exception.SetSentryMechanism("ANR", handled: false); + exception.SetSentryMechanism("MainThreadWatchdog", "Main thread unresponsive.", false); OnApplicationNotResponding?.Invoke(this, exception); } } From eab07897abd3430068df2170f6546095a595ec5e Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Thu, 9 Jan 2025 22:02:20 +0100 Subject: [PATCH 3/5] mechanism const --- src/Sentry.Unity/Integrations/AnrIntegration.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Sentry.Unity/Integrations/AnrIntegration.cs b/src/Sentry.Unity/Integrations/AnrIntegration.cs index a24bb43c3..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; @@ -80,7 +82,7 @@ protected void Report() Logger?.LogInfo("Detected an ANR event: {0}", message); var exception = new ApplicationNotRespondingException(message); - exception.SetSentryMechanism("MainThreadWatchdog", "Main thread unresponsive.", false); + exception.SetSentryMechanism(Mechanism, "Main thread unresponsive.", false); OnApplicationNotResponding?.Invoke(this, exception); } } From 43c1a29122dcf59d4b71b5bf5e1f3899548cd3c9 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Thu, 9 Jan 2025 22:02:28 +0100 Subject: [PATCH 4/5] test --- test/Sentry.Unity.Tests/AnrDetectionTests.cs | 3 +++ 1 file changed, 3 insertions(+) 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] From 6428b70695b8c7fe36a627a896e3bc16d3f97aba Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Mon, 13 Jan 2025 18:47:39 +0100 Subject: [PATCH 5/5] Updated CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) 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))