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

Lay out structure for property/method renames for v6.0 #435

Merged
merged 4 commits into from
Dec 10, 2019
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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
Changelog
=========

This release renames a few configuration properties to align better with the
intended use and other Bugsnag libraries, so people who use more than one
platform can easily find related functionality in a different library. The old
names are deprecated but still supported until the next major release.
[#435](https://github.com/bugsnag/bugsnag-cocoa/pull/435)

* `Bugsnag.setBreadcrumbCapacity()` is now `setMaxBreadcrumbs()` on the
`BugsnagConfiguration` class. In addition, the default number of breadcrumbs
saved has been raised to 25 and limited to no more than 100.
* `BugsnagConfiguration.autoNotify` is now named
`BugsnagConfiguration.autoDetectErrors`
* `BugsnagConfiguration.autoCaptureSessions` is now named
`BugsnagConfiguration.autoDetectSessions`

kattrali marked this conversation as resolved.
Show resolved Hide resolved
## 5.22.10 (2019-11-04)

### Bug fixes
Expand Down
25 changes: 13 additions & 12 deletions Source/Bugsnag.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,6 @@ static NSString *_Nonnull const BugsnagSeverityInfo = @"info";
*/
+ (void)leaveBreadcrumbForNotificationName:(NSString *_Nonnull)notificationName;

/**
* Set the maximum number of breadcrumbs to keep and sent to Bugsnag.
* By default, we'll keep and send the 20 most recent breadcrumb log
* messages.
*
* @param capacity max number of breadcrumb log messages to send
*/
+ (void)setBreadcrumbCapacity:(NSUInteger)capacity;

/**
* Clear any breadcrumbs that have been left so far.
*/
Expand All @@ -221,7 +212,7 @@ static NSString *_Nonnull const BugsnagSeverityInfo = @"info";
* By default, sessions are automatically started when the application enters the foreground.
* If you wish to manually call startSession at
* the appropriate time in your application instead, the default behaviour can be disabled via
* shouldAutoCaptureSessions.
* autoTrackSessions.
*
* Any errors which occur in an active session count towards your application's
* stability score. You can prevent errors from counting towards your stability
Expand All @@ -239,7 +230,7 @@ static NSString *_Nonnull const BugsnagSeverityInfo = @"info";
* When a session is stopped, errors will not count towards your application's
* stability score. This can be advantageous if you do not wish these calculations to
* include a certain type of error, for example, a crash in a background service.
* You should disable automatic session tracking via shouldAutoCaptureSessions if you call this method.
* You should disable automatic session tracking via autoTrackSessions if you call this method.
*
* A stopped session can be resumed by calling resumeSession,
* which will make any subsequent errors count towards your application's
Expand All @@ -255,7 +246,7 @@ static NSString *_Nonnull const BugsnagSeverityInfo = @"info";
*
* If a session has already been resumed or started and has not been stopped, calling this
* method will have no effect. You should disable automatic session tracking via
* shouldAutoCaptureSessions if you call this method.
* autoTrackSessions if you call this method.
*
* It's important to note that sessions are stored in memory for the lifetime of the
* application process and are not persisted on disk. Therefore calling this method on app
Expand All @@ -272,4 +263,14 @@ static NSString *_Nonnull const BugsnagSeverityInfo = @"info";
*/
+ (BOOL)resumeSession;

/**
* Set the maximum number of breadcrumbs to keep and sent to Bugsnag.
* By default, we'll keep and send the 20 most recent breadcrumb log
* messages.
*
* @param capacity max number of breadcrumb log messages to send
*/
+ (void)setBreadcrumbCapacity:(NSUInteger)capacity
__deprecated_msg("Use [BugsnagConfiguration setMaxBreadcrumbs:] instead");

@end
2 changes: 1 addition & 1 deletion Source/Bugsnag.m
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ + (void)leaveBreadcrumbForNotificationName:

+ (void)setBreadcrumbCapacity:(NSUInteger)capacity {
if ([self bugsnagStarted]) {
self.notifier.configuration.breadcrumbs.capacity = capacity;
[self.notifier.configuration setMaxBreadcrumbs:capacity];
}
}

Expand Down
4 changes: 2 additions & 2 deletions Source/BugsnagBreadcrumb.m
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ + (instancetype)breadcrumbWithBlock:(BSGBreadcrumbConfiguration)block {

@implementation BugsnagBreadcrumbs

NSUInteger BreadcrumbsDefaultCapacity = 20;
NSUInteger BreadcrumbsDefaultCapacity = 25;

- (instancetype)init {
static NSString *const BSGBreadcrumbCacheFileName = @"bugsnag_breadcrumbs.json";
Expand Down Expand Up @@ -263,7 +263,7 @@ - (void)setCapacity:(NSUInteger)capacity {
}
[self resizeToFitCapacity:capacity];
[self willChangeValueForKey:NSStringFromSelector(@selector(capacity))];
_capacity = capacity;
_capacity = MIN(100, capacity);
[self didChangeValueForKey:NSStringFromSelector(@selector(capacity))];
}
}
Expand Down
26 changes: 23 additions & 3 deletions Source/BugsnagConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,16 @@ NSArray<BeforeSendSession> *beforeSendSessionBlocks;
(const BSG_KSCrashReportWriter *_Nonnull writer);

/**
* YES if uncaught exceptions should be reported automatically
* YES if uncaught exceptions and other crashes should be reported automatically
*/
@property BOOL autoNotify;
@property BOOL autoDetectErrors;

/**
* Determines whether app sessions should be tracked automatically. By default this value is true.
* If this value is updated after +[Bugsnag start] is called, only subsequent automatic sessions
* will be captured.
*/
@property BOOL shouldAutoCaptureSessions;
@property BOOL autoTrackSessions;

/**
* Whether the app should report out of memory events which terminate the app
Expand Down Expand Up @@ -245,8 +245,28 @@ __deprecated_msg("This detection option is unreliable and should no longer be us
*/
- (BOOL)shouldSendReports;

/**
* The maximum number of breadcrumbs to keep and sent to Bugsnag.
* By default, we'll keep and send the 25 most recent breadcrumb log
* messages.
*/
@property NSUInteger maxBreadcrumbs;

- (void)addBeforeNotifyHook:(BugsnagBeforeNotifyHook _Nonnull)hook
__deprecated_msg("Use addBeforeSendBlock: instead.");

/**
* Determines whether app sessions should be tracked automatically. By default this value is true.
* If this value is updated after +[Bugsnag start] is called, only subsequent automatic sessions
* will be captured.
*/
@property BOOL shouldAutoCaptureSessions __deprecated_msg("Use autoTrackSessions instead");

/**
* YES if uncaught exceptions should be reported automatically
*/
@property BOOL autoNotify __deprecated_msg("Use autoDetectErrors instead");

/**
* Hooks for processing raw report data before it is sent to Bugsnag
*/
Expand Down
44 changes: 34 additions & 10 deletions Source/BugsnagConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ - (id)init {
_config = [[BugsnagMetaData alloc] init];
_apiKey = @"";
_sessionURL = [NSURL URLWithString:@"https://sessions.bugsnag.com"];
_autoNotify = YES;
_autoDetectErrors = YES;
_notifyURL = [NSURL URLWithString:BSGDefaultNotifyUrl];
_beforeNotifyHooks = [NSMutableArray new];
_beforeSendBlocks = [NSMutableArray new];
_beforeSendSessionBlocks = [NSMutableArray new];
_notifyReleaseStages = nil;
_breadcrumbs = [BugsnagBreadcrumbs new];
_automaticallyCollectBreadcrumbs = YES;
_shouldAutoCaptureSessions = YES;
_autoTrackSessions = YES;
#if !DEBUG
_reportOOMs = YES;
#endif
Expand Down Expand Up @@ -142,20 +142,28 @@ - (void)setReleaseStage:(NSString *)newReleaseStage {
}
}

@synthesize autoNotify = _autoNotify;
@synthesize autoDetectErrors = _autoDetectErrors;

- (BOOL)autoNotify {
return _autoNotify;
- (BOOL)autoDetectErrors {
return _autoDetectErrors;
}

- (void)setAutoNotify:(BOOL)shouldAutoNotify {
if (shouldAutoNotify == _autoNotify) {
- (void)setAutoDetectErrors:(BOOL)autoDetectErrors {
if (autoDetectErrors == _autoDetectErrors) {
return;
}
[self willChangeValueForKey:NSStringFromSelector(@selector(autoNotify))];
_autoNotify = shouldAutoNotify;
[self willChangeValueForKey:NSStringFromSelector(@selector(autoDetectErrors))];
_autoDetectErrors = autoDetectErrors;
[[Bugsnag notifier] updateCrashDetectionSettings];
[self didChangeValueForKey:NSStringFromSelector(@selector(autoNotify))];
[self didChangeValueForKey:NSStringFromSelector(@selector(autoDetectErrors))];
}

- (BOOL)autoNotify {
return self.autoDetectErrors;
}

- (void)setAutoNotify:(BOOL)autoNotify {
self.autoDetectErrors = autoNotify;
}

@synthesize notifyReleaseStages = _notifyReleaseStages;
Expand All @@ -177,6 +185,14 @@ - (void)setNotifyReleaseStages:(NSArray *)newNotifyReleaseStages;
}
}

- (void)setShouldAutoCaptureSessions:(BOOL)shouldAutoCaptureSessions {
self.autoTrackSessions = shouldAutoCaptureSessions;
}

- (BOOL)shouldAutoCaptureSessions {
return self.autoTrackSessions;
}

@synthesize automaticallyCollectBreadcrumbs = _automaticallyCollectBreadcrumbs;

- (BOOL)automaticallyCollectBreadcrumbs {
Expand Down Expand Up @@ -282,4 +298,12 @@ - (BOOL)hasValidApiKey {
return [_apiKey length] > 0;
}

- (NSUInteger)maxBreadcrumbs {
return self.breadcrumbs.capacity;
}

- (void)setMaxBreadcrumbs:(NSUInteger)capacity {
self.breadcrumbs.capacity = capacity;
}

@end
2 changes: 1 addition & 1 deletion Source/BugsnagCrashSentry.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ - (void)install:(BugsnagConfiguration *)config
[BSG_KSCrash sharedInstance].onCrash = onCrash;
[BSG_KSCrash sharedInstance].maxStoredReports = BSG_MAX_STORED_REPORTS;

if (!config.autoNotify) {
if (!config.autoDetectErrors) {
bsg_kscrash_setHandlingCrashTypes(BSG_KSCrashTypeUserReported);
}
if (![[BSG_KSCrash sharedInstance] install]) {
Expand Down
8 changes: 4 additions & 4 deletions Source/BugsnagNotifier.m
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ - (void)start {
#endif

_started = YES;
// autoNotify disables all unhandled event reporting
BOOL configuredToReportOOMs = self.configuration.reportOOMs && self.configuration.autoNotify;
// autoDetectErrors disables all unhandled event reporting
BOOL configuredToReportOOMs = self.configuration.reportOOMs && self.configuration.autoDetectErrors;
// Disable if a debugger is enabled, since the development cycle of starting
// and restarting an app is also an uncatchable kill
BOOL noDebuggerEnabled = !bsg_ksmachisBeingTraced();
Expand Down Expand Up @@ -806,7 +806,7 @@ - (void)lowMemoryWarning:(NSNotification *)notif {
#endif

- (void)updateCrashDetectionSettings {
if (self.configuration.autoNotify) {
if (self.configuration.autoDetectErrors) {
// Enable all crash detection
bsg_kscrash_setHandlingCrashTypes(BSG_KSCrashTypeAll);
if (self.configuration.reportOOMs) {
Expand All @@ -815,7 +815,7 @@ - (void)updateCrashDetectionSettings {
} else {
// Only enable support for notify()-based reports
bsg_kscrash_setHandlingCrashTypes(BSG_KSCrashTypeUserReported);
// autoNotify gates all unhandled report detection
// autoDetectErrors gates all unhandled report detection
[self.oomWatchdog disable];
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/BugsnagSessionTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extern NSString *const BSGSessionUpdateNotification;

/**
Record a new auto-captured session if neededed. Auto-captured sessions are only
recorded and sent if -[BugsnagConfiguration shouldAutoCaptureSessions] is YES
recorded and sent if -[BugsnagConfiguration autoTrackSessions] is YES
*/
- (void)startNewSessionIfAutoCaptureEnabled;

Expand Down
2 changes: 1 addition & 1 deletion Source/BugsnagSessionTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ - (BugsnagSession *)runningSession {
}

- (void)startNewSessionIfAutoCaptureEnabled {
if (self.config.shouldAutoCaptureSessions && [self.config shouldSendReports]) {
if (self.config.autoTrackSessions) {
[self startNewSessionWithAutoCaptureValue:YES];
}
}
Expand Down
7 changes: 6 additions & 1 deletion Tests/BugsnagBreadcrumbsTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ - (void)setUp {
}

- (void)testDefaultCapacity {
XCTAssertTrue([BugsnagBreadcrumbs new].capacity == 20);
XCTAssertTrue([BugsnagBreadcrumbs new].capacity == 25);
}

- (void)testDefaultCount {
Expand Down Expand Up @@ -63,6 +63,11 @@ - (void)testMaxBreadcrumbs {
XCTAssertNil(self.crumbs[3]);
}

- (void)testMaxMaxBreadcrumbs {
self.crumbs.capacity = 250;
XCTAssertEqual(100, self.crumbs.capacity);
}

- (void)testClearBreadcrumbs {
[self.crumbs clearBreadcrumbs];
awaitBreadcrumbSync(self.crumbs);
Expand Down
2 changes: 1 addition & 1 deletion Tests/BugsnagConfigurationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ - (void)testDefaultReleaseStage {

- (void)testDefaultSessionConfig {
BugsnagConfiguration *config = [BugsnagConfiguration new];
XCTAssertTrue([config shouldAutoCaptureSessions]);
XCTAssertTrue([config autoTrackSessions]);
}

- (void)testDefaultReportOOMs {
Expand Down
2 changes: 1 addition & 1 deletion Tests/BugsnagSessionTrackerStopTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ - (void)setUp {
[super setUp];
self.configuration = [BugsnagConfiguration new];
self.configuration.apiKey = @"test";
self.configuration.shouldAutoCaptureSessions = NO;
self.configuration.autoTrackSessions = NO;
self.tracker = [[BugsnagSessionTracker alloc] initWithConfig:self.configuration postRecordCallback:nil];
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/BugsnagSessionTrackerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ - (void)testStartNewAutoCapturedSessionWithUser {

- (void)testStartNewAutoCapturedSessionWithAutoCaptureDisabled {
XCTAssertNil(self.sessionTracker.runningSession);
self.configuration.shouldAutoCaptureSessions = NO;
self.configuration.autoTrackSessions = NO;
[self.sessionTracker startNewSessionIfAutoCaptureEnabled];
BugsnagSession *session = self.sessionTracker.runningSession;

Expand Down
2 changes: 1 addition & 1 deletion Tests/BugsnagSinkTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ - (void)setUp {
options:0
error:nil];
BugsnagConfiguration *config = [BugsnagConfiguration new];
config.autoNotify = NO;
config.autoDetectErrors = NO;
config.apiKey = @"apiKeyHere";
// This value should not appear in the assertions, as it is not equal to
// the release stage in the serialized report
Expand Down
29 changes: 29 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Upgrading

Guide to ease migrations between significant changes

## v5 -> v6

Version 6 introduces a number of property and method renames:
kattrali marked this conversation as resolved.
Show resolved Hide resolved

### `BugsnagConfiguration` class

```diff
let config = BugsnagConfiguration()

+ config.setMaxBreadcrumbs()

- config.autoNotify
+ config.autoDetectErrors

- config.autoCaptureSessions
+ config.autoTrackSessions
```

### `Bugsnag` class

```diff
- Bugsnag.setBreadcrumbCapacity(40)
let config = BugsnagConfiguration()
+ config.setMaxBreadcrumbs(40)
```
Loading