feat: ios native anr capture#2679
Conversation
Instructions and example for changelogPlease add an entry to Example: ## Unreleased
### Features
- ios native anr capture ([#2679](https://github.com/getsentry/sentry-unity/pull/2679))If none of the above apply, you can opt out of this check by adding |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c3b5f3b. Configure here.
| OptionsSetInt(cOptions, "enableNetworkBreadcrumbs", 0); | ||
|
|
||
| Logger?.LogDebug("Setting EnableAppHangTracking: {0}", options.IosNativeAnrEnabled); | ||
| OptionsSetInt(cOptions, "enableAppHangTracking", options.IosNativeAnrEnabled ? 1 : 0); |
There was a problem hiding this comment.
macOS gets duplicate ANR detection from iOS-specific flag
Medium Severity
SentryCocoaBridgeProxy.Init() is shared between iOS and macOS, and now unconditionally sets enableAppHangTracking based on IosNativeAnrEnabled (which defaults to true). On macOS, this enables native app-hang tracking, but unlike the iOS branch, DisableAnrIntegration() is never called — so both the native sentry-cocoa watchdog and the C# AnrIntegration run simultaneously, likely producing duplicate ANR reports on macOS.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit c3b5f3b. Configure here.


What does it do
This PR allows Unity users to set
enableAppHangTrackingthrough theSentryUnityOptionsviaIosNativeAnrEnabled.Why does it do it
On iOS, the Unity player loop runs on the main thread (the one with the
CFRunLoop). The generatedUnityAppController.mmregisters Unity's frame tick as aCADisplayLinkcallback on the main run loop. EveryUpdate,FixedUpdate, andLateUpdateexecute on that single thread. Native UIKit/AppKit events share the same queue.So when a Unity script blocks (e.g. infinite loop in
Update, synchronous I/O, deadlock on.Wait()), it blocks the iOS main run loop directly.sentry-cocoa's watchdog enqueues a block on the main queue and times its execution. That means if Unity is stuck, that block never runs, and that hang is reported.This is effectively replacing the Unity SDK C# ANR integration. The generated native ANR event contains an actual stack trace, making the report actually actionable.
How does it do it
We add a new flag
IosNativeAnrEnabledthat mirrors theAndroidNativeAnrEnabled. But unlike on Android, this replaces the C# watchdog entirely. We will need to follow up on this for Android as well. But the idea is to deprecate the `AnrThe resulting native event contains a fully symbolicated stack trace of the C# code that caused the freeze.
Follow up
We'll need to work on the in-app frames to clean up the stack trace presentation.