Skip to content

Commit

Permalink
Merge pull request #760 from bugsnag/release-v6.1.2
Browse files Browse the repository at this point in the history
Release v6.1.2
  • Loading branch information
tomlongridge authored Jul 21, 2020
2 parents 9251dc0 + 8dbb450 commit 9166ac7
Show file tree
Hide file tree
Showing 24 changed files with 150 additions and 91 deletions.
4 changes: 2 additions & 2 deletions Bugsnag.podspec.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Bugsnag",
"version": "6.1.1",
"version": "6.1.2",
"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.1.1"
"tag": "v6.1.2"
},
"frameworks": [
"Foundation",
Expand Down
4 changes: 2 additions & 2 deletions Bugsnag.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1480,7 +1480,6 @@
008969112486DAD000DC48C2 /* BSG_KSMachApple.h */,
008969122486DAD000DC48C2 /* BSG_KSString.h */,
008969132486DAD000DC48C2 /* BSG_KSMach.c */,
008969142486DAD000DC48C2 /* BSG_RFC3339DateTool.m */,
008969152486DAD000DC48C2 /* BSG_KSLogger.h */,
008969162486DAD000DC48C2 /* BSG_KSBacktrace_Private.h */,
008969172486DAD000DC48C2 /* BSG_KSMach_Arm64.c */,
Expand All @@ -1498,7 +1497,6 @@
008969242486DAD000DC48C2 /* BSG_KSString.c */,
008969252486DAD000DC48C2 /* BSG_KSObjC.c */,
008969262486DAD000DC48C2 /* BSG_KSLogger.m */,
008969272486DAD000DC48C2 /* BSG_RFC3339DateTool.h */,
008969282486DAD000DC48C2 /* BSG_KSMach.h */,
);
path = Tools;
Expand Down Expand Up @@ -1685,6 +1683,8 @@
00AD1CF524869EE500A27979 /* Helpers */ = {
isa = PBXGroup;
children = (
008969272486DAD000DC48C2 /* BSG_RFC3339DateTool.h */,
008969142486DAD000DC48C2 /* BSG_RFC3339DateTool.m */,
008968112486DA5600DC48C2 /* BSGSerialization.h */,
008968162486DA5600DC48C2 /* BSGSerialization.m */,
008968102486DA5600DC48C2 /* BugsnagCollections.h */,
Expand Down
7 changes: 2 additions & 5 deletions Bugsnag/BSGOutOfMemoryWatchdog.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#import "BugsnagSessionTracker.h"
#import "Private.h"
#import "BugsnagErrorTypes.h"
#import "BSG_RFC3339DateTool.h"

@interface BSGOutOfMemoryWatchdog ()
@property(nonatomic, getter=isWatching) BOOL watching;
Expand All @@ -26,10 +27,6 @@ @interface BSGOutOfMemoryWatchdog ()
@property(nonatomic) NSString *codeBundleId;
@end

@interface Bugsnag ()
+ (NSDateFormatter *_Nonnull)payloadDateFormatter;
@end

@implementation BSGOutOfMemoryWatchdog

- (instancetype)init {
Expand Down Expand Up @@ -152,7 +149,7 @@ - (void)handleTransitionToBackground:(NSNotification *)note {
}

- (void)handleLowMemoryChange:(NSNotification *)note {
self.cachedFileInfo[@"device"][@"lowMemory"] = [[Bugsnag payloadDateFormatter]
self.cachedFileInfo[@"device"][@"lowMemory"] = [BSG_RFC3339DateTool
stringFromDate:[NSDate date]];
[self writeSentinelFile];
}
Expand Down
11 changes: 0 additions & 11 deletions Bugsnag/Bugsnag.m
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,6 @@ + (BOOL)resumeSession {
}
}

+ (NSDateFormatter *)payloadDateFormatter {
static NSDateFormatter *formatter;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
formatter = [NSDateFormatter new];
formatter.dateFormat = @"yyyy'-'MM'-'dd'T'HH':'mm':'ssZZZ";
formatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
});
return formatter;
}

+ (void)addRuntimeVersionInfo:(NSString *)info
withKey:(NSString *)key {
if ([self bugsnagStarted]) {
Expand Down
6 changes: 1 addition & 5 deletions Bugsnag/Client/BugsnagClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,6 @@ @interface BugsnagUser ()
- (instancetype)initWithDictionary:(NSDictionary *)dict;
@end

@interface Bugsnag ()
+ (NSDateFormatter *_Nonnull)payloadDateFormatter;
@end

@interface BugsnagBreadcrumbs ()
@property(nonatomic, readwrite, strong) NSMutableArray *breadcrumbs;
@end
Expand Down Expand Up @@ -1177,7 +1173,7 @@ - (void)orientationChanged:(NSNotification *)notification {
}

- (void)lowMemoryWarning:(NSNotification *)notif {
[self.state addMetadata:[[Bugsnag payloadDateFormatter] stringFromDate:[NSDate date]]
[self.state addMetadata:[BSG_RFC3339DateTool stringFromDate:[NSDate date]]
withKey:BSEventLowMemoryWarning
toSection:BSGKeyDeviceState];

Expand Down
29 changes: 12 additions & 17 deletions Bugsnag/Delivery/BugsnagSessionTrackingApiClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@ - (void)deliverSessionsInStore:(BugsnagSessionFileStore *)store {
NSDictionary<NSString *, NSDictionary *> *filesWithIds = [store allFilesByName];

for (NSString *fileId in [filesWithIds allKeys]) {
// skip dupe requests
if ([self isActiveRequest:fileId]) {
continue;

// De-duplicate files as deletion of the file is asynchronous and so multiple calls
// to this method will result in multiple send requests
@synchronized (self.activeIds) {
if ([self.activeIds containsObject:fileId]) {
continue;
}
[self.activeIds addObject:fileId];
}
// add request
[self.activeIds addObject:fileId];

BugsnagSession *session = [[BugsnagSession alloc] initWithDictionary:filesWithIds[fileId]];

Expand All @@ -64,7 +67,6 @@ - (void)deliverSessionsInStore:(BugsnagSessionFileStore *)store {
initWithSessions:@[session]
config:[Bugsnag configuration]
codeBundleId:self.codeBundleId];
NSUInteger sessionCount = payload.sessions.count;
NSMutableDictionary *data = [payload toJson];
NSDictionary *HTTPHeaders = @{
@"Bugsnag-Payload-Version": @"1.0",
Expand All @@ -77,26 +79,19 @@ - (void)deliverSessionsInStore:(BugsnagSessionFileStore *)store {
headers:HTTPHeaders
onCompletion:^(NSUInteger sentCount, BOOL success, NSError *error) {
if (success && error == nil) {
bsg_log_info(@"Sent %lu sessions to Bugsnag", (unsigned long) sessionCount);
bsg_log_info(@"Sent session %@ to Bugsnag", session.id);
[store deleteFileWithId:fileId];
} else {
bsg_log_warn(@"Failed to send sessions to Bugsnag: %@", error);
}

// remove request
[self.activeIds removeObject:fileId];
@synchronized (self.activeIds) {
[self.activeIds removeObject:fileId];
}
}];
}];
}
}

- (BOOL)isActiveRequest:(NSString *)fileId {
for (NSString *val in self.activeIds) {
if ([val isEqualToString:fileId]) {
return true;
}
}
return false;
}

@end
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,49 @@

#import "BSG_RFC3339DateTool.h"

@interface BSG_RFC3339DateTool ()
+ (NSDateFormatter *)iosFormatterInstance;
@end

@implementation BSG_RFC3339DateTool

static NSString *const kDateFormatterKey = @"RfcDateFormatter";
static NSString *const kRfcDateFormatterKey = @"RfcDateFormatter";
static NSString *const kIsoDateFormatterKey = @"IsoDateFormatter";

+ (NSDateFormatter *)sharedInstance {
NSMutableDictionary *threadDict = [[NSThread currentThread] threadDictionary];
NSDateFormatter *formatter = threadDict[kDateFormatterKey];

NSDateFormatter *formatter = threadDict[kRfcDateFormatterKey];
if (formatter == nil) {
formatter = [NSDateFormatter new];
NSLocale *locale =
[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
[formatter setLocale:locale];
[formatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"];
[formatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
threadDict[kDateFormatterKey] = formatter;
threadDict[kRfcDateFormatterKey] = formatter;
}

formatter = threadDict[kRfcDateFormatterKey];
return formatter;
}

/**
Used internally to convert any dates with timezones (from older notifier versions) to Zulu time
*/
+ (NSDateFormatter *)iosFormatterInstance {
NSMutableDictionary *threadDict = [[NSThread currentThread] threadDictionary];
NSDateFormatter *formatter = threadDict[kIsoDateFormatterKey];
if (formatter == nil) {
formatter = [NSDateFormatter new];
NSLocale *locale =
[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
[formatter setLocale:locale];
[formatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ssZZZ"];
[formatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
threadDict[kIsoDateFormatterKey] = formatter;
}

formatter = threadDict[kIsoDateFormatterKey];
return formatter;
}

Expand All @@ -55,7 +81,11 @@ + (NSDate *)dateFromString:(NSString *)string {
if (![string isKindOfClass:[NSString class]]) {
return nil;
}
return [[self sharedInstance] dateFromString:string];
NSDate *date = [[self sharedInstance] dateFromString:string];
if (!date) {
date = [[self iosFormatterInstance] dateFromString:string];
}
return date;
}

+ (NSString *)stringFromUNIXTimestamp:(unsigned long long)timestamp {
Expand Down
5 changes: 5 additions & 0 deletions Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrash.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@
*/
- (NSArray<BugsnagThread *> *)captureThreads:(NSException *)exc depth:(int)depth;

/**
* Collects information about the application's foreground state (duration in foreground/background)
*/
- (NSDictionary *)captureAppStats;

/** If YES, reports will be sent even if a debugger is attached
*
* Default: NO
Expand Down
12 changes: 12 additions & 0 deletions Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrash.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#import "BugsnagThread.h"
#import "BSGSerialization.h"
#import "BugsnagErrorReportSink.h"
#import "BugsnagCollections.h"
#import "BSG_KSCrashReportFields.h"

#if BSG_HAS_UIKIT
#import <UIKit/UIKit.h>
Expand Down Expand Up @@ -320,6 +322,16 @@ - (void)sendAllReports {
return @[];
}

- (NSDictionary *)captureAppStats {
BSG_KSCrash_State state = crashContext()->state;
bsg_kscrashstate_updateDurationStats(&state);
NSMutableDictionary *dict = [NSMutableDictionary new];
BSGDictSetSafeObject(dict, @(state.activeDurationSinceLaunch), @BSG_KSCrashField_ActiveTimeSinceLaunch);
BSGDictSetSafeObject(dict, @(state.backgroundDurationSinceLaunch), @BSG_KSCrashField_BGTimeSinceLaunch);
BSGDictSetSafeObject(dict, @(state.applicationIsInForeground), @BSG_KSCrashField_AppInFG);
return dict;
}

- (void)reportUserException:(NSString *)name
reason:(NSString *)reason
handledState:(NSDictionary *)handledState
Expand Down
1 change: 0 additions & 1 deletion Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrashC.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,4 @@ char *bsg_kscrash_captureThreadTrace(int discardDepth, int frameCount, uintptr_t
bsg_kscrashsentry_resume_threads_user(false);
}
return trace;

}
8 changes: 8 additions & 0 deletions Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrashState.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ void bsg_kscrashstate_notifyAppCrash(BSG_KSCrashType type);
*/
const BSG_KSCrash_State *bsg_kscrashstate_currentState(void);

/**
* Updates the stats for duration in foreground/background. This needs to
* be updated whenever an error report is captured.
*
* @param state the kscrash state
*/
void bsg_kscrashstate_updateDurationStats(BSG_KSCrash_State *const state);

#ifdef __cplusplus
}
#endif
Expand Down
13 changes: 8 additions & 5 deletions Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrashState.m
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,15 @@ void bsg_kscrashstate_notifyAppTerminate(void) {
void bsg_kscrashstate_notifyAppCrash(BSG_KSCrashType type) {
BSG_KSCrash_State *const state = bsg_g_state;
const char *const stateFilePath = bsg_g_stateFilePath;
bsg_kscrashstate_updateDurationStats(state);
BOOL didCrash = type != BSG_KSCrashTypeUserReported;
state->crashedThisLaunch |= didCrash;
if (didCrash) {
bsg_kscrashstate_i_saveState(state, stateFilePath);
}
}

void bsg_kscrashstate_updateDurationStats(BSG_KSCrash_State *const state) {
const double duration = bsg_ksmachtimeDifferenceInSeconds(
mach_absolute_time(), state->appStateTransitionTime);
if (state->applicationIsActive) {
Expand All @@ -366,11 +374,6 @@ void bsg_kscrashstate_notifyAppCrash(BSG_KSCrashType type) {
state->backgroundDurationSinceLaunch += duration;
state->backgroundDurationSinceLastCrash += duration;
}
BOOL didCrash = type != BSG_KSCrashTypeUserReported;
state->crashedThisLaunch |= didCrash;
if (didCrash) {
bsg_kscrashstate_i_saveState(state, stateFilePath);
}
}

const BSG_KSCrash_State *bsg_kscrashstate_currentState(void) {
Expand Down
3 changes: 3 additions & 0 deletions Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSSystemInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#import "BSG_KSLogger.h"
#import "BSG_KSCrashReportFields.h"
#import "BSG_KSMach.h"
#import "BSG_KSCrash.h"

#import <CommonCrypto/CommonDigest.h>
#if BSG_PLATFORM_IOS || BSG_PLATFORM_TVOS
Expand Down Expand Up @@ -416,6 +417,8 @@ + (NSDictionary *)systemInfo {
};
BSGDictSetSafeObject(sysInfo, memory, @BSG_KSSystemField_Memory);

NSDictionary *statsInfo = [[BSG_KSCrash sharedInstance] captureAppStats];
BSGDictSetSafeObject(sysInfo, statsInfo, @BSG_KSCrashField_AppStats);
return sysInfo;
}

Expand Down
11 changes: 4 additions & 7 deletions Bugsnag/Payload/BugsnagBreadcrumb.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#import "BSG_RFC3339DateTool.h"

#import "BugsnagBreadcrumb.h"
#import "BugsnagBreadcrumbs.h"
#import "Bugsnag.h"
Expand Down Expand Up @@ -72,10 +74,6 @@ BSGBreadcrumbType BSGBreadcrumbTypeFromString(NSString *value) {
}
}

@interface Bugsnag ()
+ (NSDateFormatter *_Nonnull)payloadDateFormatter;
@end

@implementation BugsnagBreadcrumb

- (instancetype)init {
Expand All @@ -93,8 +91,7 @@ - (BOOL)isValid {

- (NSDictionary *)objectValue {
@synchronized (self) {
NSString *timestamp =
[[Bugsnag payloadDateFormatter] stringFromDate:_timestamp];
NSString *timestamp = [BSG_RFC3339DateTool stringFromDate:_timestamp];
if (timestamp && _message.length > 0) {
NSMutableDictionary *metadata = [NSMutableDictionary new];
for (NSString *key in _metadata) {
Expand Down Expand Up @@ -212,7 +209,7 @@ + (instancetype)breadcrumbFromDict:(NSDictionary *)dict {
return [self breadcrumbWithBlock:^(BugsnagBreadcrumb *crumb) {
crumb.message = dict[BSGKeyMessage] ?: dict[BSGKeyName];
crumb.metadata = dict[BSGKeyMetadata] ?: dict[@"metadata"];
crumb.timestamp = [[Bugsnag payloadDateFormatter] dateFromString:dict[BSGKeyTimestamp]];
crumb.timestamp = [BSG_RFC3339DateTool dateFromString:dict[BSGKeyTimestamp]];
crumb.type = BSGBreadcrumbTypeFromString(dict[BSGKeyType]);
}];
}
Expand Down
Loading

0 comments on commit 9166ac7

Please sign in to comment.