sentry-cocoa icon indicating copy to clipboard operation
sentry-cocoa copied to clipboard

Disable App Hang report in low memory conditions

Open eaigner opened this issue 1 year ago • 1 comments

Problem Statement

I have several users that run a 64GB dev machine and still somehow manage to fill up their entire RAM until the OS starts paging - thus appearing as a hang.

PNG image

I propose to introduce a free memory limit for reporting app hangs. Set it to a default of lets say 500MB of memory that must be free for the hang to be reported.

Solution Brainstorm

No response

Are you willing to submit a PR?

No response

eaigner avatar Jun 28 '24 21:06 eaigner

Hey @eaigner thanks for the suggestion - we'll discuss if we want to add this. In the mean time, you could use beforeSend to filter App Hang events you don't want, like described in our docs.

For example you could do the following:

options.beforeSend = { event in
  if (event.exceptions?.first?.type == "App Hanging") {
    if let freeMemory = event.context?["device"]?["free_memory"] as? UInt64, freeMemory < 50 * 1024 * 1024 {
      return nil
    }
  }
  return event
}

Note, however, that free_memory will contain the actual free memory as reported by the system (and in Sentry) and does not include quickly usable memory such as inactive.

kahest avatar Jul 01 '24 16:07 kahest

The snippet provided is the solution we suggest. The SDK has no way to detect whether the APP hang is caused by memory swap or a actual problem of the app.

brustolin avatar Jul 10 '24 12:07 brustolin