Skip to content

feat: ios native app hang capture#2679

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

feat: ios native app hang capture#2679
bitsandfoxes wants to merge 15 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 a new flag EnableAppHangTracking (default true) and a companion AppHangTimeout (default 5s) to sentry-cocoa (mapped to enableAppHangTracking and appHangTimeoutInterval). When enabled on iOS, this automatically replaces the Unity SDK's C# ANR integration at runtime. The Editor's Advanced tab gains separate C# Watchdog and AppHangTracking sections so the two mechanisms are configurable side by side.

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 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. If Unity is stuck, that block never runs, and the hang is reported. The generated native event contains an actual stack trace, making the report actionable.

Note: This is not true on macOS. sentry-cocoa does not provide app hang detection there. So EnableAppHangTracking is wired through on iOS only for now. On every other platform the option is currently a no-op.

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

@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 cf3baf5

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
Comment thread src/Sentry.Unity.iOS/SentryNativeCocoa.cs
Comment thread src/Sentry.Unity.iOS/SentryCocoaBridgeProxy.cs Outdated
@bitsandfoxes bitsandfoxes requested a review from a team May 21, 2026 11:19
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 cf3baf5. Configure here.

Comment thread src/Sentry.Unity.iOS/SentryNativeCocoa.cs
@bitsandfoxes bitsandfoxes changed the title feat: ios native anr capture feat: ios native app hang capture May 22, 2026
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.

2 participants