Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add mechanism to ANR event #1955

Merged
merged 5 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 6 additions & 1 deletion src/Sentry.Unity/Integrations/AnrIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/Sentry.Unity.Tests/AnrDetectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using UnityEngine;
using UnityEngine.TestTools;
using Sentry.Extensibility;
using Sentry.Protocol;
using Sentry.Unity.Integrations;
using Sentry.Unity.Tests.SharedClasses;

Expand Down Expand Up @@ -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]
Expand Down
Loading