Skip to content

Commit c4a818a

Browse files
authored
feat(ios): Forward experimental enableWatchdogTerminationsV2 to sentry-cocoa (#7012)
* feat(ios): Forward experimental enableWatchdogTerminationsV2 to sentry-cocoa On sentry-cocoa 9 the watchdog termination integration uses the frame-based ANR tracker (V2). A foreground app that does not render reads as an ongoing hang, so the integration skips a watchdog termination that happens during that time, even with enableAppHangTracking off. sentry-cocoa 9.6.0 added experimental.enableWatchdogTerminationsV2, which switches the integration to a run loop observer, but React Native apps could not set it from JS. RNSentryStart now reads _experiments.enableWatchdogTerminationsV2 and sets it through RNSentryExperimentalOptions, the same way as enableUnhandledCPPExceptionsV2. The option is iOS only and defaults to false. Closes #6992 * docs(changelog): Add PR link for enableWatchdogTerminationsV2 Replace the PR number placeholder in the changelog entry with #7012.
1 parent 0636a15 commit c4a818a

7 files changed

Lines changed: 99 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@
88
99
## Unreleased
1010

11+
### Features
12+
13+
- Add the experimental `_experiments.enableWatchdogTerminationsV2` option on iOS ([#7012](https://github.com/getsentry/sentry-react-native/pull/7012))
14+
- The default tracker reports a foreground app that does not render as an app hang, and the SDK does not report watchdog terminations (for example OOM kills) that happen during that time. The option uses a run loop observer instead.
15+
16+
```js
17+
Sentry.init({
18+
dsn: '__DSN__',
19+
_experiments: {
20+
enableWatchdogTerminationsV2: true,
21+
},
22+
});
23+
```
24+
1125
### Dependencies
1226

1327
- Bump Android SDK from v8.62.0 to v8.63.0 ([#6990](https://github.com/getsentry/sentry-react-native/pull/6990))

‎packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryTests.m‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,60 @@ - (void)testStartCreateOptionsWithDictionaryEnableUnhandledCPPExceptionsV2Defaul
765765
@"enableUnhandledCPPExceptionsV2 should default to disabled");
766766
}
767767

768+
- (void)testStartCreateOptionsWithDictionaryEnableWatchdogTerminationsV2Enabled
769+
{
770+
NSError *error = nil;
771+
772+
NSDictionary *_Nonnull mockedReactNativeDictionary = @{
773+
@"dsn" : @"https://abcd@efgh.ingest.sentry.io/123456",
774+
@"_experiments" : @ {
775+
@"enableWatchdogTerminationsV2" : @YES,
776+
},
777+
};
778+
SentryOptions *actualOptions =
779+
[RNSentryStart createOptionsWithDictionary:mockedReactNativeDictionary error:&error];
780+
781+
XCTAssertNotNil(actualOptions, @"Did not create sentry options");
782+
XCTAssertNil(error, @"Should not pass no error");
783+
XCTAssertTrue(actualOptions.experimental.enableWatchdogTerminationsV2,
784+
@"enableWatchdogTerminationsV2 should be enabled");
785+
}
786+
787+
- (void)testStartCreateOptionsWithDictionaryEnableWatchdogTerminationsV2Disabled
788+
{
789+
NSError *error = nil;
790+
791+
NSDictionary *_Nonnull mockedReactNativeDictionary = @{
792+
@"dsn" : @"https://abcd@efgh.ingest.sentry.io/123456",
793+
@"_experiments" : @ {
794+
@"enableWatchdogTerminationsV2" : @NO,
795+
},
796+
};
797+
SentryOptions *actualOptions =
798+
[RNSentryStart createOptionsWithDictionary:mockedReactNativeDictionary error:&error];
799+
800+
XCTAssertNotNil(actualOptions, @"Did not create sentry options");
801+
XCTAssertNil(error, @"Should not pass no error");
802+
XCTAssertFalse(actualOptions.experimental.enableWatchdogTerminationsV2,
803+
@"enableWatchdogTerminationsV2 should be disabled");
804+
}
805+
806+
- (void)testStartCreateOptionsWithDictionaryEnableWatchdogTerminationsV2Default
807+
{
808+
NSError *error = nil;
809+
810+
NSDictionary *_Nonnull mockedReactNativeDictionary = @{
811+
@"dsn" : @"https://abcd@efgh.ingest.sentry.io/123456",
812+
};
813+
SentryOptions *actualOptions =
814+
[RNSentryStart createOptionsWithDictionary:mockedReactNativeDictionary error:&error];
815+
816+
XCTAssertNotNil(actualOptions, @"Did not create sentry options");
817+
XCTAssertNil(error, @"Should not pass no error");
818+
XCTAssertFalse(actualOptions.experimental.enableWatchdogTerminationsV2,
819+
@"enableWatchdogTerminationsV2 should default to disabled");
820+
}
821+
768822
- (void)testStartEventFromSentryCocoaReactNativeHasOriginAndEnvironmentTags
769823
{
770824
SentryEvent *testEvent = [[SentryEvent alloc] init];

‎packages/core/etc/sentry-react-native.api.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ export interface BaseReactNativeOptions {
200200
replaysSessionSampleRate?: number;
201201
replaysOnErrorSampleRate?: number;
202202
enableUnhandledCPPExceptionsV2?: boolean;
203+
enableWatchdogTerminationsV2?: boolean;
203204
profilingOptions?: ProfilingOptions;
204205
androidProfilingOptions?: ProfilingOptions;
205206
enableStandaloneAppStartTracing?: boolean;

‎packages/core/ios/RNSentryExperimentalOptions.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ NS_ASSUME_NONNULL_BEGIN
2121
*/
2222
+ (BOOL)getEnableUnhandledCPPExceptionsV2:(SentryOptions *)sentryOptions;
2323

24+
/**
25+
* Sets the enableWatchdogTerminationsV2 experimental option on SentryOptions
26+
* @param sentryOptions The SentryOptions instance to configure
27+
* @param enabled Whether to enable watchdog terminations V2
28+
*/
29+
+ (void)setEnableWatchdogTerminationsV2:(BOOL)enabled sentryOptions:(SentryOptions *)sentryOptions;
30+
2431
/**
2532
* Sets the enableLogs experimental option on SentryOptions
2633
* @param sentryOptions The SentryOptions instance to configure

‎packages/core/ios/RNSentryExperimentalOptions.m‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ + (BOOL)getEnableUnhandledCPPExceptionsV2:(SentryOptions *)sentryOptions
2020
return sentryOptions.experimental.enableUnhandledCPPExceptionsV2;
2121
}
2222

23+
+ (void)setEnableWatchdogTerminationsV2:(BOOL)enabled sentryOptions:(SentryOptions *)sentryOptions
24+
{
25+
if (sentryOptions == nil) {
26+
return;
27+
}
28+
sentryOptions.experimental.enableWatchdogTerminationsV2 = enabled;
29+
}
30+
2331
+ (void)setEnableLogs:(BOOL)enabled sentryOptions:(SentryOptions *)sentryOptions
2432
{
2533
if (sentryOptions == nil) {

‎packages/core/ios/RNSentryStart.m‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ + (SentryOptions *_Nullable)createOptionsWithDictionary:(NSDictionary *_Nonnull)
188188
[RNSentryExperimentalOptions setEnableUnhandledCPPExceptionsV2:enableUnhandledCPPExceptions
189189
sentryOptions:sentryOptions];
190190

191+
BOOL enableWatchdogTerminationsV2 =
192+
[experiments[@"enableWatchdogTerminationsV2"] boolValue];
193+
[RNSentryExperimentalOptions setEnableWatchdogTerminationsV2:enableWatchdogTerminationsV2
194+
sentryOptions:sentryOptions];
195+
191196
// Configure iOS UI Profiling
192197
NSDictionary *profilingOptions = experiments[@"profilingOptions"];
193198
if (profilingOptions != nil && [profilingOptions isKindOfClass:[NSDictionary class]]) {

‎packages/core/src/js/options.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,16 @@ export interface BaseReactNativeOptions {
633633
*/
634634
enableUnhandledCPPExceptionsV2?: boolean;
635635

636+
/**
637+
* Experiment: Detects watchdog terminations (for example OOM kills) with a run loop observer instead of the frame-based ANR tracker.
638+
*
639+
* With the default tracker, a foreground app that does not render reads as an app hang, and the SDK does not report watchdog terminations that happen during that time.
640+
*
641+
* @default false
642+
* @platform ios
643+
*/
644+
enableWatchdogTerminationsV2?: boolean;
645+
636646
/**
637647
* Configuration options for UI profiling.
638648
* It supports two modes: `manual` and `trace`.

0 commit comments

Comments
 (0)