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: Added ApplicationNotRespondingException type #1800

Merged
merged 3 commits into from
Sep 12, 2024
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

### Features

- Added an `ApplicationNotRespondingException` type that allows filtering of ANR events ([#1800](https://github.com/getsentry/sentry-unity/pull/1800))

### Dependencies

- Bump CLI from v2.34.1 to v2.36.1 ([#1788](https://github.com/getsentry/sentry-unity/pull/1788), [#1792](https://github.com/getsentry/sentry-unity/pull/1792), [#1796](https://github.com/getsentry/sentry-unity/pull/1796))
Expand Down
12 changes: 3 additions & 9 deletions src/Sentry.Unity/Integrations/AnrIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading;
using Sentry.Extensibility;
using Sentry.Integrations;
using Sentry.Unity.Integrations;
using UnityEngine;

namespace Sentry.Unity;
Expand Down Expand Up @@ -51,7 +52,7 @@ internal abstract class AnrWatchDog
protected readonly int SleepIntervalMs;
protected readonly IDiagnosticLogger? Logger;
protected readonly SentryMonoBehaviour MonoBehaviour;
internal event EventHandler<ApplicationNotResponding> OnApplicationNotResponding = delegate { };
internal event EventHandler<ApplicationNotRespondingException> OnApplicationNotResponding = delegate { };
protected bool Paused { get; private set; } = false;

internal AnrWatchDog(IDiagnosticLogger? logger, SentryMonoBehaviour monoBehaviour, TimeSpan detectionTimeout)
Expand All @@ -77,7 +78,7 @@ 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 ApplicationNotResponding(message));
OnApplicationNotResponding?.Invoke(this, new ApplicationNotRespondingException(message));
}
}
}
Expand Down Expand Up @@ -192,10 +193,3 @@ private IEnumerator UpdateUiStatus()
}
}
}

internal class ApplicationNotResponding : Exception
{
internal ApplicationNotResponding() : base() { }
internal ApplicationNotResponding(string message) : base(message) { }
internal ApplicationNotResponding(string message, Exception innerException) : base(message, innerException) { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace Sentry.Unity.Integrations;

public class ApplicationNotRespondingException : Exception
{
internal ApplicationNotRespondingException() : base() { }
internal ApplicationNotRespondingException(string message) : base(message) { }
internal ApplicationNotRespondingException(string message, Exception innerException) : base(message, innerException) { }
}
11 changes: 6 additions & 5 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.Unity.Integrations;
using Sentry.Unity.Tests.SharedClasses;

namespace Sentry.Unity.Tests;
Expand Down Expand Up @@ -43,7 +44,7 @@ private AnrWatchDog CreateWatchDog(bool multiThreaded)
[UnityTest]
public IEnumerator DetectsStuckUI([ValueSource(nameof(MultiThreadingTestValues))] bool multiThreaded)
{
ApplicationNotResponding? arn = null;
ApplicationNotRespondingException? arn = null;
_sut = CreateWatchDog(multiThreaded);
_sut.OnApplicationNotResponding += (_, e) => arn = e;

Expand Down Expand Up @@ -71,7 +72,7 @@ public IEnumerator DetectsStuckUI([ValueSource(nameof(MultiThreadingTestValues))
[UnityTest]
public IEnumerator DoesntReportWorkingUI([ValueSource(nameof(MultiThreadingTestValues))] bool multiThreaded)
{
ApplicationNotResponding? arn = null;
ApplicationNotRespondingException? arn = null;
_sut = CreateWatchDog(multiThreaded);
_sut.OnApplicationNotResponding += (_, e) => arn = e;

Expand All @@ -90,7 +91,7 @@ public IEnumerator DoesntReportWorkingUI([ValueSource(nameof(MultiThreadingTestV
[TestCase(false)]
public void DoesntReportShortlyStuckUI(bool multiThreaded)
{
ApplicationNotResponding? arn = null;
ApplicationNotRespondingException? arn = null;
_sut = CreateWatchDog(multiThreaded);
_sut.OnApplicationNotResponding += (_, e) => arn = e;

Expand All @@ -103,7 +104,7 @@ public void DoesntReportShortlyStuckUI(bool multiThreaded)
[UnityTest]
public IEnumerator DoesntReportWhilePaused([ValueSource(nameof(MultiThreadingTestValues))] bool multiThreaded)
{
ApplicationNotResponding? arn = null;
ApplicationNotRespondingException? arn = null;
_sut = CreateWatchDog(multiThreaded);
_sut.OnApplicationNotResponding += (_, e) => arn = e;

Expand Down Expand Up @@ -132,7 +133,7 @@ public IEnumerator DoesntReportWhilePaused([ValueSource(nameof(MultiThreadingTes
[UnityTest]
public IEnumerator IsNotAffectedByTimeScale()
{
ApplicationNotResponding? anr = null;
ApplicationNotRespondingException? anr = null;
_sut = CreateWatchDog(true);
_sut.OnApplicationNotResponding += (_, e) => anr = e;

Expand Down
Loading