Skip to content

Commit

Permalink
feat(apple): Rename the OOM integration (#5938)
Browse files Browse the repository at this point in the history
OOM is now called watchdog terminations. See getsentry/sentry-cocoa#2499, which will be part of the 8.0.0 release of sentry-cocoa.

Co-authored-by: Isabel <[email protected]>
Co-authored-by: Philipp Hofmann <[email protected]>
  • Loading branch information
3 people authored Jan 10, 2023
1 parent 3bcff8f commit 2101195
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ This integration will swizzle some methods to create breadcrumbs. For example, f

This integration registers for lifecycle notifications and automatically starts and ends sessions required for [Release health](/product/releases/health/#session).

### SentryOutOfMemoryTrackingIntegration
### SentryWatchdogTerminationsTrackingIntegration

This integration tracks out-of-memory crashes based on heuristics. This feature is available for iOS, tvOS, and Mac Catalyst and works only if the application was in the foreground. Check out the <PlatformLink to="/configuration/out-of-memory/">configuration</PlatformLink> information for more details.
This integration tracks watchdog terminations based on heuristics. This feature is available for iOS, tvOS, and Mac Catalyst and works only if the application was in the foreground. Check out the <PlatformLink to="/configuration/watchdog-terminations/">configuration</PlatformLink> information for more details.

## Disable an Integration

Expand Down
23 changes: 13 additions & 10 deletions src/platforms/apple/common/configuration/out-of-memory.mdx
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
---
title: Out Of Memory
sidebar_order: 10
description: "Learn how to turn off Out Of Memory"
description: "Learn how to turn off Out Of Memory tracking"
---

<Note>
This integration is only available before the 8.0.0 release of the Sentry Apple SDK. We renamed it to <PlatformLink to="/configuration/watchdog-terminations/">watchdog terminations</PlatformLink> in the 8.0.0 release.
</Note>

This integration tracks out-of-memory (OOM) crashes based on heuristics. This feature is available for iOS, tvOS, and Mac Catalyst, works only if the application was in the foreground, and doesn't track OOMs for unit tests.

When a typical unhandled error occurs, the Apple SDK writes a report to disk with the current state of your application, with details like the stack trace, tags, breadcrumbs, and so on, before the app terminates. With OOM crashes, the operating system can kill your app without further notice, which means the SDK can't write a report to disk.
As a result, in the Apple SDK, we track OOM crashes during the app start based on heuristics, but getting the state of the app when an OOM occurs is challenging. To provide the same state as we do for a typical crash, we would periodically need to store the app state to disk. This would cause a lot of I/O, which in turn could negatively affect the application's performance. To avoid this, OOM events have less context than typical unhandled errors.

When a user launches the app, the SDK checks the following statements and reports an OOM if all of them are true:

* The app didn't crash on the previous run.
* The app was in the foreground/active.
* The user launched the app at least once. When your app produces an OOM during the first launch, the SDK can't detect it.
* There was no debugger attached to the process of the app. If there was, our logic would falsely report OOMs whenever you restarted the app in development.
* The app is not running on a simulator.
* The OS did not update your app.
* The user didn't update the OS of their device.
* The user didn't terminate the app manually, and neither did the OS.
- The app didn't crash on the previous run.
- The app was in the foreground/active.
- The user launched the app at least once. When your app produces an OOM during the first launch, the SDK can't detect it.
- There was no debugger attached to the process of the app. (If there was, our logic would falsely report OOMs whenever you restarted the app in development.)
- The app is not running on a simulator.
- The OS did not update your app.
- The user didn't update the OS of their device.
- The user didn't terminate the app manually, and neither did the OS.

If you're interested in the implementation details, you can check out [the code](https://github.com/getsentry/sentry-cocoa/blob/master/Sources/Sentry/SentryOutOfMemoryLogic.m) to find out more.

Expand All @@ -40,5 +44,4 @@ SentrySDK.start { options in
options.dsn = @"___PUBLIC_DSN___";
options.enableOutOfMemoryTracking = NO;
}];

```
48 changes: 48 additions & 0 deletions src/platforms/apple/common/configuration/watchdog-terminations.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: Watchdog Terminations
sidebar_order: 10
description: "Learn how to turn off Watchdog Termination tracking"
---

<Note>
This integration is available since version 8.0.0 of Sentry Apple SDK. It was named <PlatformLink to="/configuration/out-of-memory/">Out of Memory</PlatformLink> before the 8.0.0 release.
</Note>

This integration tracks [watchdog terminations](https://developer.apple.com/documentation/xcode/addressing-watchdog-terminations) based on heuristics. This feature is available for iOS, tvOS, and Mac Catalyst, works only if the application was in the foreground, and doesn't track watchdog terminations for unit tests.

When a typical unhandled error occurs, the Apple SDK writes a report to disk with the current state of your application, with details like the stack trace, tags, breadcrumbs, and so on, before the app terminates. When the watchdog terminates your app this happens without further notice, which means the SDK can't write a report to disk. A common reason the watchdog can terminate your app is an Out Of Memory problem. If the app is terminated because it hangs, we don't create a watchdog termination event, but instead an `AppHangs` event is created.

As a result, in the Apple SDK, we track watchdog terminations during the app start based on heuristics, but getting the state of the app when a watchdog termination occurs is challenging. To provide the same state as we do for a typical crash, we would periodically need to store the app state to disk. This would cause a lot of I/O, which in turn could negatively affect the application's performance. To avoid this, watchdog termination events have less context than typical unhandled errors. Breadcrumbs are stored to disk and are added to watchdog termination events to help you figure out where in the app the event happened. This is done by appending the breadcrumbs to an open file, which should have a marginal impact on your app's performance.

When a user launches the app, the SDK checks the following statements and reports a watchdog termination if all of them are true:

- The app didn't crash on the previous run.
- The app was in the foreground/active.
- The user launched the app at least once. When your app was killed by the watchdog during the first launch, the SDK can't detect it.
- There was no debugger attached to the process of the app. (If there was, our logic would falsely report watchdog terminations whenever you restarted the app in development.)
- The app was not running on a simulator.
- The OS didn't update your app.
- The user didn't update the OS of their device.
- The user didn't terminate the app manually, and neither did the OS.

If you're interested in the implementation details, you can check out [the code](https://github.com/getsentry/sentry-cocoa/blob/master/Sources/Sentry/SentryWatchdogTerminationsLogic.m) to find out more.

If you'd like to opt out of this feature, you can do so using options:

```swift {tabTitle:Swift}
import Sentry

SentrySDK.start { options in
options.dsn = "___PUBLIC_DSN___"
options.enableWatchdogTerminationTracking = false
}
```

```objc {tabTitle:Objective-C}
@import Sentry;

[SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
options.dsn = @"___PUBLIC_DSN___";
options.enableWatchdogTerminationTracking = NO;
}];
```

1 comment on commit 2101195

@vercel
Copy link

@vercel vercel bot commented on 2101195 Jan 10, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

sentry-docs – ./

sentry-docs-git-master.sentry.dev
sentry-docs.sentry.dev
docs.sentry.io

Please sign in to comment.