Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Rename OOM to Watchdog Terminations #2499

Merged
merged 9 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ This version adds a dependency on Swift.
- Rename `SentryOptions.enableCoreDataTracking` to `enableCoreDataTracing`
- SentrySDK.close calls flush, which is a blocking call (#2453)
- Bump minimum Xcode version to 13 (#2483)
- Rename `SentryOptions.enableOutOfMemoryTracking` to `SentryOptions.enableWatchdogTerminationsTracking` (#2499)

## 8.0.0-beta.4

Expand Down
100 changes: 50 additions & 50 deletions Sentry.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Sentry.xcodeproj/xcshareddata/xcschemes/Sentry.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
Identifier = "SentryNetworkTrackerIntegrationTests/testGetRequest_SpanCreatedAndBaggageHeaderAdded_disabled()">
</Test>
<Test
Identifier = "SentryOutOfMemoryIntegrationTests/testANRDetected_UpdatesAppStateToTrue_disabled()">
Identifier = "SentryWatchdogTerminationsIntegrationTests/testANRDetected_UpdatesAppStateToTrue_disabled()">
</Test>
<Test
Identifier = "SentryProfilerSwiftTests/testProfileTimeoutTimer_disabled()">
Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/Public/SentryOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ NS_SWIFT_NAME(Options)
@property (nonatomic, assign) BOOL enableAutoSessionTracking;

/**
* Whether to enable out of memory tracking or not. Default is YES.
* Whether to enable Watchdog Terminations tracking or not. Default is YES.
*/
@property (nonatomic, assign) BOOL enableOutOfMemoryTracking;
@property (nonatomic, assign) BOOL enableWatchdogTerminationsTracking;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

enableWatchdogTerminationsTracking or enableWatchdogTerminationTracking, not 100% sure which is better.

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer enableWatchdogTerminationTracking

Copy link
Member

Choose a reason for hiding this comment

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

I would have also preferred enableWatchdogTerminationTracking

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR is now open with that change.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you @kevinrenskers 😀


/**
* The interval to end a session if the App goes to the background.
Expand Down
6 changes: 3 additions & 3 deletions Sources/Sentry/SentryBaseIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ - (BOOL)shouldBeEnabledWithOptions:(SentryOptions *)options
return NO;
}

if ((integrationOptions & kIntegrationOptionEnableOutOfMemoryTracking)
&& !options.enableOutOfMemoryTracking) {
[self logWithOptionName:@"enableOutOfMemoryTracking"];
if ((integrationOptions & kIntegrationOptionEnableWatchdogTerminationsTracking)
&& !options.enableWatchdogTerminationsTracking) {
[self logWithOptionName:@"enableWatchdogTerminationsTracking"];
return NO;
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Sentry/SentryClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#import "SentryMeta.h"
#import "SentryNSError.h"
#import "SentryOptions+Private.h"
#import "SentryOutOfMemoryTracker.h"
#import "SentryPermissionsObserver.h"
#import "SentrySDK+Private.h"
#import "SentryScope+Private.h"
Expand All @@ -45,6 +44,7 @@
#import "SentryUIDeviceWrapper.h"
#import "SentryUser.h"
#import "SentryUserFeedback.h"
#import "SentryWatchdogTerminationsTracker.h"

#if SENTRY_HAS_UIKIT
# import <UIKit/UIKit.h>
Expand Down Expand Up @@ -738,7 +738,7 @@ - (BOOL)isOOM:(SentryEvent *)event isCrashEvent:(BOOL)isCrashEvent

SentryException *exception = event.exceptions[0];
return exception.mechanism != nil &&
[exception.mechanism.type isEqualToString:SentryOutOfMemoryMechanismType];
[exception.mechanism.type isEqualToString:SentryWatchdogTerminationMechanismType];
}

- (void)applyPermissionsToEvent:(SentryEvent *)event
Expand Down
12 changes: 6 additions & 6 deletions Sources/Sentry/SentryCrashIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#import "SentryEvent.h"
#import "SentryHub.h"
#import "SentryInAppLogic.h"
#import "SentryOutOfMemoryLogic.h"
#import "SentrySDK+Private.h"
#import "SentryScope+Private.h"
#import "SentrySessionCrashedHandler.h"
#import "SentryWatchdogTerminationsLogic.h"
#import <SentryAppStateManager.h>
#import <SentryClient+Private.h>
#import <SentryCrashScopeObserver.h>
Expand Down Expand Up @@ -70,13 +70,13 @@ - (BOOL)installWithOptions:(nonnull SentryOptions *)options

SentryAppStateManager *appStateManager =
[SentryDependencyContainer sharedInstance].appStateManager;
SentryOutOfMemoryLogic *logic =
[[SentryOutOfMemoryLogic alloc] initWithOptions:options
crashAdapter:self.crashAdapter
appStateManager:appStateManager];
SentryWatchdogTerminationsLogic *logic =
[[SentryWatchdogTerminationsLogic alloc] initWithOptions:options
crashAdapter:self.crashAdapter
appStateManager:appStateManager];
self.crashedSessionHandler =
[[SentrySessionCrashedHandler alloc] initWithCrashWrapper:self.crashAdapter
outOfMemoryLogic:logic];
watchdogTerminationsLogic:logic];

self.scopeObserver =
[[SentryCrashScopeObserver alloc] initWithMaxBreadcrumbs:options.maxBreadcrumbs];
Expand Down
8 changes: 4 additions & 4 deletions Sources/Sentry/SentryOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ - (void)setMeasurement:(SentryMeasurementValue *)measurement
#endif
@"SentryFramesTrackingIntegration", @"SentryAutoBreadcrumbTrackingIntegration",
@"SentryAutoSessionTrackingIntegration", @"SentryAppStartTrackingIntegration",
@"SentryOutOfMemoryTrackingIntegration", @"SentryPerformanceTrackingIntegration",
@"SentryNetworkTrackingIntegration", @"SentryFileIOTrackingIntegration",
@"SentryCoreDataTrackingIntegration"
@"SentryWatchdogTerminationsTrackingIntegration",
@"SentryPerformanceTrackingIntegration", @"SentryNetworkTrackingIntegration",
@"SentryFileIOTrackingIntegration", @"SentryCoreDataTrackingIntegration"
]
.mutableCopy;

Expand All @@ -65,7 +65,7 @@ - (instancetype)init
_defaultSampleRate = @1;
self.sampleRate = _defaultSampleRate;
self.enableAutoSessionTracking = YES;
self.enableOutOfMemoryTracking = YES;
self.enableWatchdogTerminationsTracking = YES;
self.sessionTrackingIntervalMillis = [@30000 unsignedIntValue];
self.attachStacktrace = YES;
self.stitchAsyncCode = NO;
Expand Down
11 changes: 6 additions & 5 deletions Sources/Sentry/SentrySessionCrashedHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,33 @@
#import "SentryCurrentDate.h"
#import "SentryFileManager.h"
#import "SentryHub.h"
#import "SentryOutOfMemoryLogic.h"
#import "SentrySDK+Private.h"
#import "SentryWatchdogTerminationsLogic.h"

@interface
SentrySessionCrashedHandler ()

@property (nonatomic, strong) SentryCrashWrapper *crashWrapper;
@property (nonatomic, strong) SentryOutOfMemoryLogic *outOfMemoryLogic;
@property (nonatomic, strong) SentryWatchdogTerminationsLogic *watchdogTerminationsLogic;

@end

@implementation SentrySessionCrashedHandler

- (instancetype)initWithCrashWrapper:(SentryCrashWrapper *)crashWrapper
outOfMemoryLogic:(SentryOutOfMemoryLogic *)outOfMemoryLogic;
watchdogTerminationsLogic:(SentryWatchdogTerminationsLogic *)watchdogTerminationsLogic;
{
self = [self init];
self.crashWrapper = crashWrapper;
self.outOfMemoryLogic = outOfMemoryLogic;
self.watchdogTerminationsLogic = watchdogTerminationsLogic;

return self;
}

- (void)endCurrentSessionAsCrashedWhenCrashOrOOM
{
if (self.crashWrapper.crashedLastLaunch || [self.outOfMemoryLogic isOOM]) {
if (self.crashWrapper.crashedLastLaunch ||
[self.watchdogTerminationsLogic isWatchdogTermination]) {
SentryFileManager *fileManager = [[[SentrySDK currentHub] getClient] fileManager];

if (nil == fileManager) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
#import <SentryAppStateManager.h>
#import <SentryCrashWrapper.h>
#import <SentryOptions.h>
#import <SentryOutOfMemoryLogic.h>
#import <SentrySDK+Private.h>
#import <SentryWatchdogTerminationsLogic.h>

#if SENTRY_HAS_UIKIT
# import <UIKit/UIKit.h>
#endif

@interface
SentryOutOfMemoryLogic ()
SentryWatchdogTerminationsLogic ()

@property (nonatomic, strong) SentryOptions *options;
@property (nonatomic, strong) SentryCrashWrapper *crashAdapter;
@property (nonatomic, strong) SentryAppStateManager *appStateManager;

@end

@implementation SentryOutOfMemoryLogic
@implementation SentryWatchdogTerminationsLogic

- (instancetype)initWithOptions:(SentryOptions *)options
crashAdapter:(SentryCrashWrapper *)crashAdapter
Expand All @@ -33,9 +33,9 @@ - (instancetype)initWithOptions:(SentryOptions *)options
return self;
}

- (BOOL)isOOM
- (BOOL)isWatchdogTermination
{
if (!self.options.enableOutOfMemoryTracking) {
if (!self.options.enableWatchdogTerminationsTracking) {
return NO;
}

Expand Down Expand Up @@ -79,18 +79,19 @@ - (BOOL)isOOM
return NO;
}

// The app crashed on the previous run. No OOM.
// The app crashed on the previous run. No Watchdog Termination.
if (self.crashAdapter.crashedLastLaunch) {
return NO;
}

// The SDK wasn't running, so *any* crash after the SDK got closed would be seen as OOM.
// The SDK wasn't running, so *any* crash after the SDK got closed would be seen as a Watchdog
// Termination.
if (!previousAppState.isSDKRunning) {
return NO;
}

// Was the app in foreground/active ?
// If the app was in background we can't reliably tell if it was an OOM or not.
// If the app was in background we can't reliably tell if it was a Watchdog Termination or not.
if (!previousAppState.isActive) {
return NO;
}
Expand All @@ -99,16 +100,16 @@ - (BOOL)isOOM
return NO;
}

// When calling SentrySDK.start twice we would wrongly report an OOM. We can only
// report an OOM when the SDK is started the first time.
// When calling SentrySDK.start twice we would wrongly report a Watchdog Termination. We can
// only report a Watchdog Termination when the SDK is started the first time.
if (SentrySDK.startInvocations != 1) {
return NO;
}

return YES;
#else
// We can only track OOMs for iOS, tvOS and macCatalyst. Therefore we return NO for other
// platforms.
// We can only track Watchdog Terminations for iOS, tvOS and macCatalyst. Therefore we return NO
// for other platforms.
return NO;
#endif
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#import "SentryOutOfMemoryScopeObserver.h"
#import "SentryWatchdogTerminationsScopeObserver.h"
#import <SentryBreadcrumb.h>
#import <SentryFileManager.h>
#import <SentryLog.h>

@interface
SentryOutOfMemoryScopeObserver ()
SentryWatchdogTerminationsScopeObserver ()

@property (strong, nonatomic) SentryFileManager *fileManager;
@property (strong, nonatomic) NSFileHandle *fileHandle;
Expand All @@ -14,7 +14,7 @@

@end

@implementation SentryOutOfMemoryScopeObserver
@implementation SentryWatchdogTerminationsScopeObserver

- (instancetype)initWithMaxBreadcrumbs:(NSInteger)maxBreadcrumbs
fileManager:(SentryFileManager *)fileManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,36 @@
#import <SentryMechanism.h>
#import <SentryMessage.h>
#import <SentryOptions.h>
#import <SentryOutOfMemoryLogic.h>
#import <SentryOutOfMemoryTracker.h>
#import <SentrySDK+Private.h>
#import <SentryWatchdogTerminationsLogic.h>
#import <SentryWatchdogTerminationsTracker.h>

#if SENTRY_HAS_UIKIT
# import <UIKit/UIKit.h>
#endif

@interface
SentryOutOfMemoryTracker ()
SentryWatchdogTerminationsTracker ()

@property (nonatomic, strong) SentryOptions *options;
@property (nonatomic, strong) SentryOutOfMemoryLogic *outOfMemoryLogic;
@property (nonatomic, strong) SentryWatchdogTerminationsLogic *watchdogTerminationsLogic;
@property (nonatomic, strong) SentryDispatchQueueWrapper *dispatchQueue;
@property (nonatomic, strong) SentryAppStateManager *appStateManager;
@property (nonatomic, strong) SentryFileManager *fileManager;

@end

@implementation SentryOutOfMemoryTracker
@implementation SentryWatchdogTerminationsTracker

- (instancetype)initWithOptions:(SentryOptions *)options
outOfMemoryLogic:(SentryOutOfMemoryLogic *)outOfMemoryLogic
watchdogTerminationsLogic:(SentryWatchdogTerminationsLogic *)watchdogTerminationsLogic
appStateManager:(SentryAppStateManager *)appStateManager
dispatchQueueWrapper:(SentryDispatchQueueWrapper *)dispatchQueueWrapper
fileManager:(SentryFileManager *)fileManager
{
if (self = [super init]) {
self.options = options;
self.outOfMemoryLogic = outOfMemoryLogic;
self.watchdogTerminationsLogic = watchdogTerminationsLogic;
self.appStateManager = appStateManager;
self.dispatchQueue = dispatchQueueWrapper;
self.fileManager = fileManager;
Expand All @@ -55,7 +55,7 @@ - (void)start
[self.appStateManager start];

[self.dispatchQueue dispatchAsyncWithBlock:^{
if ([self.outOfMemoryLogic isOOM]) {
if ([self.watchdogTerminationsLogic isWatchdogTermination]) {
SentryEvent *event = [[SentryEvent alloc] initWithLevel:kSentryLevelFatal];
// Set to empty list so no breadcrumbs of the current scope are added
event.breadcrumbs = @[];
Expand All @@ -76,10 +76,10 @@ - (void)start
}

SentryException *exception =
[[SentryException alloc] initWithValue:SentryOutOfMemoryExceptionValue
type:SentryOutOfMemoryExceptionType];
[[SentryException alloc] initWithValue:SentryWatchdogTerminationExceptionValue
type:SentryWatchdogTerminationExceptionType];
SentryMechanism *mechanism =
[[SentryMechanism alloc] initWithType:SentryOutOfMemoryMechanismType];
[[SentryMechanism alloc] initWithType:SentryWatchdogTerminationMechanismType];
mechanism.handled = @(NO);
exception.mechanism = mechanism;
event.exceptions = @[ exception ];
Expand All @@ -90,7 +90,8 @@ - (void)start
}
}];
#else
SENTRY_LOG_INFO(@"NO UIKit -> SentryOutOfMemoryTracker will not track OOM.");
SENTRY_LOG_INFO(
@"NO UIKit -> SentryWatchdogTerminationsTracker will not track Watchdog Terminations.");
return;
#endif
}
Expand Down
Loading