Skip to content
Open
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

### Features

- Added `AndroidNativeAnrEnabled` (default `true`) to enable ANR detection through `sentry-java` SDK. The native ANR integration monitors the Android UI thread. On API ≥ 30 this uses [ANR v2](https://docs.sentry.io/platforms/android/configuration/app-not-respond/) via `ApplicationExitInfo` to report OS-detected ANRs from prior runs; on API < 30 it falls back to an in-process watchdog. This is complementary to the Unity SDK's C# watchdog, which monitors the Unity player loop. ([#2671](https://github.com/getsentry/sentry-unity/pull/2671))
- Added `IosNativeAnrEnabled` (default `true`) to enable ANR detection through the `sentry-cocoa` SDK. This replaces the Unity SDK's C# watchdog, monitors the Unity player loop and allows Sentry to show a stack trace for the ANR event ([#2679](https://github.com/getsentry/sentry-unity/pull/2679))
- Added `AndroidNativeAnrEnabled` (default `true`) to enable ANR detection through the `sentry-java` SDK. The native ANR integration monitors the Android UI thread. On API ≥ 30 this uses [ANR v2](https://docs.sentry.io/platforms/android/configuration/app-not-respond/) via `ApplicationExitInfo` to report OS-detected ANRs from prior runs; on API < 30 it falls back to an in-process watchdog. This is complementary to the Unity SDK's C# watchdog, which monitors the Unity player loop. ([#2671](https://github.com/getsentry/sentry-unity/pull/2671))

### Dependencies

Expand Down
2 changes: 1 addition & 1 deletion src/Sentry.Unity.Editor.iOS/NativeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal static string Generate(SentryUnityOptions options)
@""maxBreadcrumbs"": @{options.MaxBreadcrumbs},
@""maxCacheItems"": @{options.MaxCacheItems},
@""enableAutoSessionTracking"": @NO,
@""enableAppHangTracking"": @NO,
@""enableAppHangTracking"": @{ToObjCString(options.IosNativeAnrEnabled)},
@""enableCaptureFailedRequests"": @{ToObjCString(options.CaptureFailedRequests)},
@""failedRequestStatusCodes"" : @[{failedRequestStatusCodesArray}],
@""sendDefaultPii"" : @{ToObjCString(options.SendDefaultPii)},
Expand Down
8 changes: 8 additions & 0 deletions src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Runtime.InteropServices;
using Sentry.Extensibility;
using Sentry.Unity.Integrations;
using UnityEngine;

namespace Sentry.Unity.iOS;

Expand Down Expand Up @@ -66,6 +68,12 @@ public static bool Init(SentryUnityOptions options)
// See https://github.com/getsentry/sentry-unity/issues/1658
OptionsSetInt(cOptions, "enableNetworkBreadcrumbs", 0);

if (ApplicationAdapter.Instance.Platform == RuntimePlatform.IPhonePlayer)
{
Logger?.LogDebug("Setting EnableAppHangTracking: {0}", options.IosNativeAnrEnabled);
OptionsSetInt(cOptions, "enableAppHangTracking", options.IosNativeAnrEnabled ? 1 : 0);
}

Logger?.LogDebug("Setting EnableWatchdogTerminationTracking: {0}", options.IosWatchdogTerminationIntegrationEnabled);
OptionsSetInt(cOptions, "enableWatchdogTerminationTracking", options.IosWatchdogTerminationIntegrationEnabled ? 1 : 0);

Expand Down
6 changes: 6 additions & 0 deletions src/Sentry.Unity.iOS/SentryNativeCocoa.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ internal static void Configure(SentryUnityOptions options, RuntimePlatform platf
}

options.ScopeObserver = new NativeScopeObserver("iOS", options);

if (options.IosNativeAnrEnabled)
{
Logger?.LogDebug("Disabling the C# ANR watchdog on iOS - sentry-cocoa handles app hang detection.");
options.DisableAnrIntegration();
}
Comment thread
bitsandfoxes marked this conversation as resolved.
}
else
{
Expand Down
12 changes: 12 additions & 0 deletions src/Sentry.Unity/SentryUnityOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,18 @@ public sealed class SentryUnityOptions : SentryOptions
/// </summary>
public bool IosWatchdogTerminationIntegrationEnabled { get; set; } = false;

/// <summary>
/// Enables ANR (app hang) detection on iOS through the native (sentry-cocoa) SDK.
/// When enabled, sentry-cocoa monitors the main thread for hangs and the Unity SDK's
/// C# ANR watchdog is skipped on iOS to avoid duplicate reports.
/// </summary>
/// <remarks>
/// sentry-cocoa observes the iOS run loop directly, which yields more accurate
/// app-hang detection than the Unity-side watchdog. Disable this only if you want
/// to fall back to the C# watchdog.
/// </remarks>
public bool IosNativeAnrEnabled { get; set; } = true;

/// <summary>
/// Whether the SDK should initialize the native SDK before the game starts. This bakes the options at build-time into
/// the generated Xcode project. Modifying the options at runtime will not affect the options used to initialize
Expand Down
26 changes: 26 additions & 0 deletions test/Sentry.Unity.Editor.iOS.Tests/NativeOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,32 @@ public void CreateOptionsFile_NewSentryOptions_ContainsSdkNameSetting()
File.Delete(testOptionsFileName);
}

[Test]
public void CreateOptionsFile_IosNativeAnrEnabled_SetsYes()
{
const string testOptionsFileName = "testOptions.m";

NativeOptions.CreateFile(testOptionsFileName, new SentryUnityOptions { IosNativeAnrEnabled = true });

var nativeOptions = File.ReadAllText(testOptionsFileName);
StringAssert.Contains("@\"enableAppHangTracking\": @YES", nativeOptions);

File.Delete(testOptionsFileName);
}

[Test]
public void CreateOptionsFile_IosNativeAnrDisabled_SetsNo()
{
const string testOptionsFileName = "testOptions.m";

NativeOptions.CreateFile(testOptionsFileName, new SentryUnityOptions { IosNativeAnrEnabled = false });

var nativeOptions = File.ReadAllText(testOptionsFileName);
StringAssert.Contains("@\"enableAppHangTracking\": @NO", nativeOptions);

File.Delete(testOptionsFileName);
}

[Test]
public void CreateOptionsFile_FilterBadGatewayEnabled_AddsFiltering()
{
Expand Down
Loading