Skip to content

Commit

Permalink
Merge pull request #1455 from bugsnag/release-v6.22.0
Browse files Browse the repository at this point in the history
Release v6.22.0
  • Loading branch information
nickdowell authored Aug 10, 2022
2 parents 1a5afef + c989fa1 commit 6ab8116
Show file tree
Hide file tree
Showing 100 changed files with 934 additions and 459 deletions.
4 changes: 2 additions & 2 deletions .jazzy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ author_url: "https://www.bugsnag.com"
author: "Bugsnag Inc"
clean: false # avoid deleting docs/.git
framework_root: "Bugsnag"
github_file_prefix: "https://github.com/bugsnag/bugsnag-cocoa/tree/v6.21.0/Bugsnag"
github_file_prefix: "https://github.com/bugsnag/bugsnag-cocoa/tree/v6.22.0/Bugsnag"
github_url: "https://github.com/bugsnag/bugsnag-cocoa"
hide_documentation_coverage: true
module: "Bugsnag"
module_version: "6.21.0"
module_version: "6.22.0"
objc: true
output: "docs"
readme: "README.md"
Expand Down
7 changes: 5 additions & 2 deletions Bugsnag.podspec.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Bugsnag",
"version": "6.21.0",
"version": "6.22.0",
"summary": "The Bugsnag crash reporting framework for Apple platforms.",
"homepage": "https://bugsnag.com",
"license": "MIT",
Expand All @@ -9,7 +9,7 @@
},
"source": {
"git": "https://github.com/bugsnag/bugsnag-cocoa.git",
"tag": "v6.21.0"
"tag": "v6.22.0"
},
"ios": {
"frameworks": [
Expand Down Expand Up @@ -38,6 +38,9 @@
"Security"
]
},
"compiler_flags": [
"-fvisibility=hidden"
],
"libraries": [
"c++", "z"
],
Expand Down
42 changes: 32 additions & 10 deletions Bugsnag.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Bugsnag/Breadcrumbs/BSGNotificationBreadcrumbs.m
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ - (void)addBreadcrumbForNotification:(NSNotification *)notification {
[self addBreadcrumbWithType:BSGBreadcrumbTypeState forNotificationName:notification.name];
}

- (void)addBreadcrumbForTableViewNotification:(__attribute__((unused)) NSNotification *)notification {
- (void)addBreadcrumbForTableViewNotification:(__unused NSNotification *)notification {
#if BSG_HAVE_TABLE_VIEW

#if TARGET_OS_IOS || TARGET_OS_TV
Expand All @@ -375,15 +375,15 @@ - (void)addBreadcrumbForTableViewNotification:(__attribute__((unused)) NSNotific
#endif
}

- (void)addBreadcrumbForMenuItemNotification:(__attribute__((unused)) NSNotification *)notification {
- (void)addBreadcrumbForMenuItemNotification:(__unused NSNotification *)notification {
#if TARGET_OS_OSX
NSMenuItem *menuItem = [[notification userInfo] valueForKey:@"MenuItem"];
[self addBreadcrumbWithType:BSGBreadcrumbTypeState forNotificationName:notification.name metadata:
[menuItem isKindOfClass:NSMENUITEM] ? @{BSGKeyAction : menuItem.title} : nil];
#endif
}

- (void)addBreadcrumbForControlNotification:(__attribute__((unused)) NSNotification *)notification {
- (void)addBreadcrumbForControlNotification:(__unused NSNotification *)notification {
#if TARGET_OS_IOS
NSString *label = ((UIControl *)notification.object).accessibilityLabel;
[self addBreadcrumbWithType:BSGBreadcrumbTypeUser forNotificationName:notification.name metadata:
Expand Down
2 changes: 1 addition & 1 deletion Bugsnag/Breadcrumbs/BugsnagBreadcrumbs.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithConfiguration:(BugsnagConfiguration *)config;

/**
* The breadcrumbs stored in memory.
* Returns an array of new objects representing the breadcrumbs stored in memory.
*/
@property (readonly, nonatomic) NSArray<BugsnagBreadcrumb *> *breadcrumbs;

Expand Down
19 changes: 9 additions & 10 deletions Bugsnag/Breadcrumbs/BugsnagBreadcrumbs.m
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,15 @@ - (void)removeAllBreadcrumbs {
}
self.nextFileNumber = 0;
}
[self deleteBreadcrumbFiles];
dispatch_async(BSGGetFileSystemQueue(), ^{
NSError *error = nil;
NSString *directory = self.breadcrumbsPath;
NSFileManager *fileManager = [NSFileManager new];
if (![fileManager removeItemAtPath:directory error:&error] ||
![fileManager createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:&error]) {
bsg_log_debug(@"%s: %@", __FUNCTION__, error);
}
});
}

#pragma mark - File storage
Expand Down Expand Up @@ -275,15 +283,6 @@ - (NSString *)pathForFileNumber:(unsigned int)fileNumber {
return breadcrumbs;
}

- (void)deleteBreadcrumbFiles {
[[NSFileManager defaultManager] removeItemAtPath:self.breadcrumbsPath error:NULL];

NSError *error = nil;
if (![[NSFileManager defaultManager] createDirectoryAtPath:self.breadcrumbsPath withIntermediateDirectories:YES attributes:nil error:&error]) {
bsg_log_err(@"Unable to create breadcrumbs directory: %@", error);
}
}

@end

#pragma mark -
Expand Down
13 changes: 3 additions & 10 deletions Bugsnag/Bugsnag.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,11 @@

#import "Bugsnag.h"

#import "BSGKeys.h"
#import "BSG_KSCrash.h"
#import "BSGStorageMigratorV0V1.h"
#import "Bugsnag+Private.h"
#import "BugsnagBreadcrumbs.h"
#import "BugsnagLogger.h"
#import "BugsnagClient+Private.h"
#import "BugsnagConfiguration+Private.h"
#import "BugsnagMetadata+Private.h"
#import "BugsnagPlugin.h"
#import "BugsnagHandledState.h"
#import "BugsnagSystemState.h"
#import "BSGStorageMigratorV0V1.h"
#import "BugsnagLogger.h"

static BugsnagClient *bsg_g_bugsnag_client = NULL;

Expand All @@ -56,8 +49,8 @@ + (BugsnagClient *_Nonnull)startWithApiKey:(NSString *_Nonnull)apiKey {

+ (BugsnagClient *_Nonnull)startWithConfiguration:(BugsnagConfiguration *_Nonnull)configuration {
@synchronized(self) {
[BSGStorageMigratorV0V1 migrate];
if (bsg_g_bugsnag_client == nil) {
[BSGStorageMigratorV0V1 migrate];
bsg_g_bugsnag_client = [[BugsnagClient alloc] initWithConfiguration:configuration];
[bsg_g_bugsnag_client start];
} else {
Expand Down
4 changes: 4 additions & 0 deletions Bugsnag/BugsnagSessionTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#import <Bugsnag/BugsnagConfiguration.h>
#import <Bugsnag/BugsnagSession.h>

#import "BSGSessionUploader.h"

NS_ASSUME_NONNULL_BEGIN

@interface BugsnagSessionTracker : NSObject
Expand Down Expand Up @@ -82,6 +84,8 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nullable, readonly, nonatomic) BugsnagSession *runningSession;

@property (strong, nonatomic) BSGSessionUploader *sessionUploader;

- (void)addRuntimeVersionInfo:(NSString *)info
withKey:(NSString *)key;

Expand Down
13 changes: 6 additions & 7 deletions Bugsnag/BugsnagSessionTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

#import "BugsnagSessionTracker.h"

#import "BSGSessionUploader.h"
#import "BSGAppKit.h"
#import "BSGDefines.h"
#import "BSGUIKit.h"
#import "BSGWatchKit.h"
#import "BSG_KSSystemInfo.h"
#import "BugsnagApp+Private.h"
#import "BugsnagClient+Private.h"
Expand All @@ -17,10 +20,7 @@
#import "BugsnagDevice+Private.h"
#import "BugsnagLogger.h"
#import "BugsnagSession+Private.h"
#import "BSGDefines.h"
#import "BSGAppKit.h"
#import "BSGWatchKit.h"
#import "BSGUIKit.h"
#import "BugsnagUser+Private.h"

/**
Number of seconds in background required to make a new session
Expand All @@ -30,7 +30,6 @@
@interface BugsnagSessionTracker ()
@property (strong, nonatomic) BugsnagConfiguration *config;
@property (weak, nonatomic) BugsnagClient *client;
@property (strong, nonatomic) BSGSessionUploader *sessionUploader;
@property (strong, nonatomic) NSDate *backgroundStartTime;
@property (nonatomic) NSMutableDictionary *extraRuntimeInfo;
@end
Expand Down Expand Up @@ -174,7 +173,7 @@ - (void)startNewSession {

BugsnagSession *newSession = [[BugsnagSession alloc] initWithId:[[NSUUID UUID] UUIDString]
startedAt:[NSDate date]
user:self.client.user
user:[self.client.user withId]
app:app
device:device];

Expand Down
15 changes: 9 additions & 6 deletions Bugsnag/Client/BugsnagClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ - (instancetype)initWithConfiguration:(BugsnagConfiguration *)configuration {
self.breadcrumbs = [[BugsnagBreadcrumbs alloc] initWithConfiguration:self.configuration];

// Start with a copy of the configuration metadata
self.metadata = [[_configuration metadata] deepCopy];
self.metadata = [[_configuration metadata] copy];
}
return self;
}
Expand Down Expand Up @@ -312,7 +312,7 @@ - (void)start {
#endif
}

- (void)appLaunchTimerFired:(__attribute__((unused)) NSTimer *)timer {
- (void)appLaunchTimerFired:(__unused NSTimer *)timer {
[self markLaunchCompleted];
}

Expand Down Expand Up @@ -462,6 +462,7 @@ - (void)setupConnectivityListener {
__strong typeof(weakSelf) strongSelf = weakSelf;
if (connected) {
[strongSelf.eventUploader uploadStoredEvents];
[strongSelf.sessionTracker.sessionUploader processStoredSessions];
}

[strongSelf addAutoBreadcrumbOfType:BSGBreadcrumbTypeState
Expand Down Expand Up @@ -604,7 +605,7 @@ - (void)notify:(NSException *)exception block:(BugsnagOnErrorBlock)block {

- (void)notifyErrorOrException:(id)errorOrException block:(BugsnagOnErrorBlock)block {
NSDictionary *systemInfo = [BSG_KSSystemInfo systemInfo];
BugsnagMetadata *metadata = [self.metadata deepCopy];
BugsnagMetadata *metadata = [self.metadata copy];

NSArray<NSNumber *> *callStack = nil;
NSString *context = self.context;
Expand Down Expand Up @@ -682,7 +683,7 @@ - (void)notifyErrorOrException:(id)errorOrException block:(BugsnagOnErrorBlock)b
BugsnagEvent *event = [[BugsnagEvent alloc] initWithApp:[self generateAppWithState:systemInfo]
device:[self generateDeviceWithState:systemInfo]
handledState:handledState
user:self.user
user:[self.user withId]
metadata:metadata
breadcrumbs:self.breadcrumbs.breadcrumbs ?: @[]
errors:@[error]
Expand Down Expand Up @@ -725,6 +726,8 @@ - (void)notifyInternal:(BugsnagEvent *_Nonnull)event
}
}

event.user = [event.user withId];

BOOL originalUnhandledValue = event.unhandled;
@try {
if (block != nil && !block(event)) { // skip notifying if callback false
Expand Down Expand Up @@ -1032,7 +1035,7 @@ - (void)appHangDetectedAtDate:(NSDate *)date withThreads:(NSArray<BugsnagThread

NSArray<BugsnagBreadcrumb *> *breadcrumbs = [self.breadcrumbs breadcrumbsBeforeDate:date];

BugsnagMetadata *metadata = [self.metadata deepCopy];
BugsnagMetadata *metadata = [self.metadata copy];

[metadata addMetadata:BSGAppMetadataFromRunContext(bsg_runContext) toSection:BSGKeyApp];
[metadata addMetadata:BSGDeviceMetadataFromRunContext(bsg_runContext) toSection:BSGKeyDevice];
Expand All @@ -1041,7 +1044,7 @@ - (void)appHangDetectedAtDate:(NSDate *)date withThreads:(NSArray<BugsnagThread
[[BugsnagEvent alloc] initWithApp:app
device:device
handledState:handledState
user:self.configuration.user
user:[self.user withId]
metadata:metadata
breadcrumbs:breadcrumbs
errors:@[error]
Expand Down
2 changes: 0 additions & 2 deletions Bugsnag/Configuration/BugsnagConfiguration+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ NS_ASSUME_NONNULL_BEGIN

@property (readonly, nonatomic) BOOL shouldSendReports;

@property (readonly, nonatomic) NSDictionary<NSString *, id> *sessionApiHeaders;

@property (readonly, nullable, nonatomic) NSURL *sessionURL;

@property (readwrite, retain, nonnull, nonatomic) BugsnagUser *user;
Expand Down
44 changes: 16 additions & 28 deletions Bugsnag/Configuration/BugsnagConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#import "BSGConfigurationBuilder.h"
#import "BSGKeys.h"
#import "BSG_RFC3339DateTool.h"
#import "BugsnagApiClient.h"
#import "BugsnagEndpointConfiguration.h"
#import "BugsnagErrorTypes.h"
Expand Down Expand Up @@ -94,6 +93,7 @@ - (nonnull id)copyWithZone:(nullable NSZone *)zone {
[copy setSendLaunchCrashesSynchronously:self.sendLaunchCrashesSynchronously];
[copy setMaxPersistedEvents:self.maxPersistedEvents];
[copy setMaxPersistedSessions:self.maxPersistedSessions];
[copy setMaxStringValueLength:self.maxStringValueLength];
[copy setMaxBreadcrumbs:self.maxBreadcrumbs];
[copy setNotifier:self.notifier];
[copy setFeatureFlagStore:self.featureFlagStore];
Expand Down Expand Up @@ -186,9 +186,10 @@ - (instancetype)initWithApiKey:(NSString *)apiKey {
_enabledBreadcrumbTypes = BSGEnabledBreadcrumbTypeAll;
_launchDurationMillis = 5000;
_sendLaunchCrashesSynchronously = YES;
_maxBreadcrumbs = 50;
_maxBreadcrumbs = 100;
_maxPersistedEvents = 32;
_maxPersistedSessions = 128;
_maxStringValueLength = 10000;
_autoTrackSessions = YES;
#if BSG_HAVE_MACH_THREADS
_sendThreads = BSGThreadSendPolicyAlways;
Expand All @@ -201,7 +202,6 @@ - (instancetype)initWithApiKey:(NSString *)apiKey {
// Enabling OOM detection only happens in release builds, to avoid triggering
// the heuristic when killing/restarting an app in Xcode or similar.
_persistUser = YES;
// Only gets persisted user data if there is any, otherwise nil
// persistUser isn't settable until post-init.
_user = [self getPersistedUserData];

Expand Down Expand Up @@ -283,7 +283,7 @@ - (BOOL)shouldSendReports {
- (void)setUser:(NSString *_Nullable)userId
withEmail:(NSString *_Nullable)email
andName:(NSString *_Nullable)name {
self.user = [[BugsnagUser alloc] initWithUserId:userId name:name emailAddress:email];
self.user = [[BugsnagUser alloc] initWithId:userId name:name emailAddress:email];

if (self.persistUser) {
[self persistUserData];
Expand Down Expand Up @@ -360,13 +360,6 @@ - (void)removeOnBreadcrumbBlock:(BugsnagOnBreadcrumbBlock)block {
// MARK: -
// =============================================================================

- (NSDictionary *)sessionApiHeaders {
return @{BugsnagHTTPHeaderNameApiKey: self.apiKey ?: @"",
BugsnagHTTPHeaderNamePayloadVersion: @"1.0",
BugsnagHTTPHeaderNameSentAt: [BSG_RFC3339DateTool stringFromDate:[NSDate date]]
};
}

- (void)setEndpoints:(BugsnagEndpointConfiguration *)endpoints {
if ([self isValidURLString:endpoints.notify]) {
_endpoints.notify = [endpoints.notify copy];
Expand Down Expand Up @@ -410,20 +403,12 @@ - (void)setPersistUser:(BOOL)persistUser {
}
}

/**
* Retrieve a persisted user, if we have any valid, persisted fields, or nil otherwise
*/
- (BugsnagUser *)getPersistedUserData {
@synchronized(self) {
NSString *email = [userDefaults objectForKey:kBugsnagUserEmailAddress];
NSString *name = [userDefaults objectForKey:kBugsnagUserName];
NSString *userId = [userDefaults objectForKey:kBugsnagUserUserId];

if (email || name || userId) {
return [[BugsnagUser alloc] initWithUserId:userId name:name emailAddress:email];
} else {
return [[BugsnagUser alloc] initWithUserId:nil name:nil emailAddress:nil];
}
return [[BugsnagUser alloc] initWithId:userId name:name emailAddress:email];
}
}

Expand Down Expand Up @@ -524,15 +509,18 @@ - (NSUInteger)maxBreadcrumbs {
}
}

- (void)setMaxBreadcrumbs:(NSUInteger)maxBreadcrumbs {
- (void)setMaxBreadcrumbs:(NSUInteger)newValue {
static const NSUInteger maxAllowed = 500;
if (newValue > maxAllowed) {
bsg_log_err(@"Invalid configuration value detected. "
"Option maxBreadcrumbs should be an integer between 0-%lu. "
"Supplied value is %lu",
(unsigned long)maxAllowed,
(unsigned long)newValue);
return;
}
@synchronized (self) {
if (maxBreadcrumbs <= 100) {
_maxBreadcrumbs = maxBreadcrumbs;
} else {
bsg_log_err(@"Invalid configuration value detected. Option maxBreadcrumbs "
"should be an integer between 0-100. Supplied value is %lu",
(unsigned long) maxBreadcrumbs);
}
_maxBreadcrumbs = newValue;
}
}

Expand Down
4 changes: 2 additions & 2 deletions Bugsnag/Delivery/BSGConnectivity.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ BOOL BSGConnectivityShouldReportChange(SCNetworkReachabilityFlags flags) {
* Callback invoked by SCNetworkReachability, which calls an Objective-C block
* that handles the connection change.
*/
void BSGConnectivityCallback(__attribute__((unused)) SCNetworkReachabilityRef target,
void BSGConnectivityCallback(__unused SCNetworkReachabilityRef target,
SCNetworkReachabilityFlags flags,
__attribute__((unused)) void *info)
__unused void *info)
{
if (bsg_reachability_change_block && BSGConnectivityShouldReportChange(flags)) {
BOOL connected = (flags & kSCNetworkReachabilityFlagsReachable) != 0;
Expand Down
Loading

0 comments on commit 6ab8116

Please sign in to comment.