getsentry / sentry-cocoa

The official Sentry SDK for iOS, tvOS, macOS, watchOS.
https://sentry.io/for/cocoa/
MIT License
783 stars 313 forks source link

Disable App Hang report in low memory conditions #4130

Closed eaigner closed 1 week ago

eaigner commented 3 weeks ago

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

kahest commented 3 weeks ago

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.

brustolin commented 1 week ago

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.