Skip to content

Add AttachAllThreadsToAppHangs to attach all threads to native app-hang events - #2963

Draft
bitsandfoxes wants to merge 3 commits into
mainfrom
spire/stackwalk-mode
Draft

bitsandfoxes wants to merge 3 commits into
mainfrom
spire/stackwalk-mode

Conversation

@bitsandfoxes

Copy link
Copy Markdown
Contributor

Problem

With EnableAppHangTracking on, native app-hang events on Windows, Linux and macOS carry only the stack of the hung main thread. When the main thread is waiting on a job worker, the render thread or a lock, the event shows the wait but not its cause. sentry-native 0.17.7 can attach every thread's stack to app-hang events (getsentry/sentry-native#2327), but the SDK sets the native options itself and gives users no way to turn this on.

How

Users opt in with SentryUnityOptions.AttachAllThreadsToAppHangs, which is off by default. In the editor it's the Attach All Threads toggle under App Hang Tracking (Experimental) in the Advanced tab, saved in the options asset. When it's on together with EnableAppHangTracking, app-hang events also carry the names and stack traces of the other threads.

When the option is on, SentryNativeBridge.Init calls sentry_options_set_app_hang_thread_stackwalk_mode with SENTRY_THREAD_STACKWALK_MODE_ALL. With the default the setter is never called, so app-hang events stay as they are today.

  • Older console native libraries: if a native library predates 0.17.7 and lacks the function, the SDK logs a warning and native init goes ahead.
  • Switch: the function isn't bound, because Switch links the native library statically. Turning the option on there only writes a debug log.

Caveats

  • It works on Windows x64/ARM64, Linux and macOS with the native backend. It has no effect on iOS, Android, Xbox, PlayStation, Switch or Windows x86.
  • Known risks from sentry-native:
    • On Windows, the watchdog can block while it suspends a thread that holds a lock the stack walk needs, such as the heap lock.
    • On Linux, walking a thread signals it, which can end a blocking call such as sleep or poll early with EINTR.
  • The native API is experimental, and its naming may change in sentry-native v1. The bool keeps the Unity option independent of that naming.
  • This builds on the sentry-native 0.17.7 bump in chore(deps): update Native SDK to v0.17.7 #2960, and the diff includes that bump until chore(deps): update Native SDK to v0.17.7 #2960 merges.

Closes #2956

@github-actions

github-actions Bot commented Nov 25, 2026 •

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

Generated by 🚫 dangerJS against c345d81

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.

Expose sentry-native's app-hang thread stackwalk mode (attach all threads to app-hang events)

2 participants