Skip to content

feat: ios native anr capture#2679

Open
bitsandfoxes wants to merge 13 commits into
mainfrom
feat/ios-anr
Open

feat: ios native anr capture#2679
bitsandfoxes wants to merge 13 commits into
mainfrom
feat/ios-anr

Conversation

@bitsandfoxes
Copy link
Copy Markdown
Contributor

@bitsandfoxes bitsandfoxes commented May 13, 2026

Resolves https://github.com/getsentry/team-gdx/issues/151

What does it do

This PR forwards the new flag EnableAppHangTracking to sentry-cocoa (maps to enableAppHangTracking). The timeout is reused. This replaces the C# watchdog on platforms that are supported by sentry-cocoa.

Why does it do it

On iOS, the Unity player loop runs on the main thread (the one with the CFRunLoop). The generated UnityAppController.mm registers Unity's frame tick as a CADisplayLink callback on the main run loop. Every Update, FixedUpdate, and LateUpdate execute 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 allows us to replace the Unity SDK C# ANR integration. The generated native ANR event from sentry-cocoa contains an actual stack trace, making the report actually actionable.

How does it do it

We're in the process of deprecating AnrEnabled and putting the app freeze capture behaviour under EnableAppHangTracking. But unlike on Android, this replaces the C# watchdog entirely. We will need to follow up on this for Android as well, see #2681

Result

Screenshot 2026-05-13 at 16 35 22

The 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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 13, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 549ae57

Comment thread src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs Outdated
Comment thread src/Sentry.Unity.iOS/SentryNativeCocoa.cs
Base automatically changed from chore/anr-native-samples to main May 18, 2026 14:42
Comment thread src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs
Comment thread src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs
Comment thread src/Sentry.Unity.iOS/SentryNativeCocoa.cs Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a7c7670. Configure here.

Comment thread src/Sentry.Unity.iOS/SentryNativeCocoa.cs
Comment thread src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant