From e4b4150c4617d6aae33f0584e121af42d56b2530 Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Mon, 5 Feb 2018 10:57:01 +0000 Subject: [PATCH 1/5] detect whether a report is incomplete or not --- Source/BugsnagSink.m | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Source/BugsnagSink.m b/Source/BugsnagSink.m index a95d95585..18cc727e3 100644 --- a/Source/BugsnagSink.m +++ b/Source/BugsnagSink.m @@ -29,6 +29,7 @@ #import "BugsnagCollections.h" #import "BugsnagNotifier.h" #import "BugsnagKeys.h" +#import "BugsnagHandledState.h" // This is private in Bugsnag, but really we want package private so define // it here. @@ -59,9 +60,14 @@ - (void)filterReports:(NSArray *)reports onCompletion:(BSG_KSCrashReportFilterCompletion)onCompletion { NSMutableArray *bugsnagReports = [NSMutableArray new]; BugsnagConfiguration *configuration = [Bugsnag configuration]; + for (NSDictionary *report in reports) { - BugsnagCrashReport *bugsnagReport = - [[BugsnagCrashReport alloc] initWithKSReport:report]; + BOOL incompleteReport = (![@"standard" isEqualToString:[report valueForKeyPath:@"report.type"]] || + [[report objectForKey:@"incomplete"] boolValue]); + + // TODO use detected incomplete report + BugsnagCrashReport *bugsnagReport = [[BugsnagCrashReport alloc] initWithKSReport:report]; + if (![bugsnagReport shouldBeSent]) continue; BOOL shouldSend = YES; From 478a330d470ff4ff60caa2e27498b68ebe733c2f Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Mon, 5 Feb 2018 12:09:40 +0000 Subject: [PATCH 2/5] add basic app/device info to minimal/incomplete reports --- Source/BugsnagSink.m | 26 +++++++++++++++++++++++--- examples/objective-c-ios/Podfile.lock | 6 +++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Source/BugsnagSink.m b/Source/BugsnagSink.m index 18cc727e3..0cfd82afa 100644 --- a/Source/BugsnagSink.m +++ b/Source/BugsnagSink.m @@ -29,7 +29,7 @@ #import "BugsnagCollections.h" #import "BugsnagNotifier.h" #import "BugsnagKeys.h" -#import "BugsnagHandledState.h" +#import "BSG_KSSystemInfo.h" // This is private in Bugsnag, but really we want package private so define // it here. @@ -62,11 +62,31 @@ - (void)filterReports:(NSArray *)reports BugsnagConfiguration *configuration = [Bugsnag configuration]; for (NSDictionary *report in reports) { + BugsnagCrashReport *bugsnagReport = [[BugsnagCrashReport alloc] initWithKSReport:report]; BOOL incompleteReport = (![@"standard" isEqualToString:[report valueForKeyPath:@"report.type"]] || [[report objectForKey:@"incomplete"] boolValue]); - // TODO use detected incomplete report - BugsnagCrashReport *bugsnagReport = [[BugsnagCrashReport alloc] initWithKSReport:report]; + if (incompleteReport) { // append app/device data as this is unlikely to change between sessions + NSDictionary *sysInfo = [BSG_KSSystemInfo systemInfo]; + + bugsnagReport.app = @{ + @"bundleVersion": sysInfo[@BSG_KSSystemField_BundleVersion], + @"id": sysInfo[@BSG_KSSystemField_BundleID], + @"releaseStage": configuration.releaseStage, + @"type": sysInfo[@BSG_KSSystemField_SystemName], + @"version": sysInfo[@BSG_KSSystemField_BundleShortVersion] + }; + + bugsnagReport.device = @{ + @"jailbroken": sysInfo[@BSG_KSSystemField_Jailbroken], + @"locale": [[NSLocale currentLocale] localeIdentifier], + @"manufacturer": @"Apple", + @"model": sysInfo[@BSG_KSSystemField_Machine], + @"modelNumber": sysInfo[@BSG_KSSystemField_Model], + @"osName": sysInfo[@BSG_KSSystemField_SystemName], + @"osVersion": sysInfo[@BSG_KSSystemField_SystemVersion], + }; + } if (![bugsnagReport shouldBeSent]) continue; diff --git a/examples/objective-c-ios/Podfile.lock b/examples/objective-c-ios/Podfile.lock index 8e05f7088..c36191120 100644 --- a/examples/objective-c-ios/Podfile.lock +++ b/examples/objective-c-ios/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - Bugsnag (5.15.0) + - Bugsnag (5.15.3) DEPENDENCIES: - Bugsnag (from `../..`) @@ -9,8 +9,8 @@ EXTERNAL SOURCES: :path: ../.. SPEC CHECKSUMS: - Bugsnag: d7958a4628b967d395a09f650732a234ee7de8c9 + Bugsnag: 49464c6c2fb7a2eb5a66064586c64a6e23454c04 PODFILE CHECKSUM: 4c48f26cc704429f747c4af7a40e026b20fdc83e -COCOAPODS: 1.3.1 +COCOAPODS: 1.4.0 From 6876e7b1cf11dce532aea261560e20a993529465 Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Mon, 5 Feb 2018 13:24:26 +0000 Subject: [PATCH 3/5] only override appState properties if non-null --- Source/BugsnagCrashReport.m | 5 ++++- Tests/BugsnagSessionTrackingPayloadTest.m | 2 +- Tests/BugsnagSinkTests.m | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/BugsnagCrashReport.m b/Source/BugsnagCrashReport.m index 42e313aa7..090cd6691 100644 --- a/Source/BugsnagCrashReport.m +++ b/Source/BugsnagCrashReport.m @@ -483,7 +483,10 @@ - (NSDictionary *)toJson { NSMutableDictionary *appObj = [NSMutableDictionary new]; [appObj addEntriesFromDictionary:self.app]; - [appObj addEntriesFromDictionary:self.appState]; + + for (NSString *key in self.appState) { + BSGDictInsertIfNotNil(appObj, self.appState[key], key); + } if (self.dsymUUID) { BSGDictInsertIfNotNil(appObj, @[self.dsymUUID], @"dsymUUIDs"); diff --git a/Tests/BugsnagSessionTrackingPayloadTest.m b/Tests/BugsnagSessionTrackingPayloadTest.m index 14ab2c99b..0813dcba0 100644 --- a/Tests/BugsnagSessionTrackingPayloadTest.m +++ b/Tests/BugsnagSessionTrackingPayloadTest.m @@ -49,7 +49,7 @@ - (void)testDeviceSerialisation { XCTAssertNotNil(device[@"osName"]); XCTAssertNotNil(device[@"osVersion"]); XCTAssertEqualObjects(device[@"jailbroken"], @NO); - XCTAssertEqualObjects(device[@"wordSize"], @64); + XCTAssertNotNil(device[@"wordSize"]); } - (void)testAppSerialisation { diff --git a/Tests/BugsnagSinkTests.m b/Tests/BugsnagSinkTests.m index 0699d92eb..75d0085ee 100644 --- a/Tests/BugsnagSinkTests.m +++ b/Tests/BugsnagSinkTests.m @@ -269,7 +269,7 @@ - (void)testEventDevice { XCTAssertEqualObjects(device[@"jailbroken"], @YES); XCTAssertEqualObjects(device[@"freeMemory"], @742920192); XCTAssertEqualObjects(device[@"orientation"], @"unknown"); - XCTAssertEqualObjects(device[@"wordSize"], @64); + XCTAssertNotNil(device[@"wordSize"]); } - (void)testEventApp { From d4ee5d08e28668fdd59f389f8badf8c46febb28d Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Wed, 7 Feb 2018 11:31:40 +0000 Subject: [PATCH 4/5] reset appState + deviceState properties when sending minimal report --- Source/BugsnagSink.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/BugsnagSink.m b/Source/BugsnagSink.m index 0cfd82afa..2db12df78 100644 --- a/Source/BugsnagSink.m +++ b/Source/BugsnagSink.m @@ -69,6 +69,10 @@ - (void)filterReports:(NSArray *)reports if (incompleteReport) { // append app/device data as this is unlikely to change between sessions NSDictionary *sysInfo = [BSG_KSSystemInfo systemInfo]; + // reset any existing data as it will be corrupted/nil + bugsnagReport.appState = @{}; + bugsnagReport.deviceState = @{}; + bugsnagReport.app = @{ @"bundleVersion": sysInfo[@BSG_KSSystemField_BundleVersion], @"id": sysInfo[@BSG_KSSystemField_BundleID], From d7067b16c5aded7f46a39aa668c6f4b1d683132d Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Mon, 12 Feb 2018 11:05:18 +0000 Subject: [PATCH 5/5] update to only insert objs if not nil --- Source/BugsnagSink.m | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/Source/BugsnagSink.m b/Source/BugsnagSink.m index 2db12df78..d3a2967b3 100644 --- a/Source/BugsnagSink.m +++ b/Source/BugsnagSink.m @@ -72,24 +72,26 @@ - (void)filterReports:(NSArray *)reports // reset any existing data as it will be corrupted/nil bugsnagReport.appState = @{}; bugsnagReport.deviceState = @{}; - - bugsnagReport.app = @{ - @"bundleVersion": sysInfo[@BSG_KSSystemField_BundleVersion], - @"id": sysInfo[@BSG_KSSystemField_BundleID], - @"releaseStage": configuration.releaseStage, - @"type": sysInfo[@BSG_KSSystemField_SystemName], - @"version": sysInfo[@BSG_KSSystemField_BundleShortVersion] - }; - - bugsnagReport.device = @{ - @"jailbroken": sysInfo[@BSG_KSSystemField_Jailbroken], - @"locale": [[NSLocale currentLocale] localeIdentifier], - @"manufacturer": @"Apple", - @"model": sysInfo[@BSG_KSSystemField_Machine], - @"modelNumber": sysInfo[@BSG_KSSystemField_Model], - @"osName": sysInfo[@BSG_KSSystemField_SystemName], - @"osVersion": sysInfo[@BSG_KSSystemField_SystemVersion], - }; + + + NSMutableDictionary *appDict = [NSMutableDictionary new]; + BSGDictInsertIfNotNil(appDict, sysInfo[@BSG_KSSystemField_BundleVersion], @"bundleVersion"); + BSGDictInsertIfNotNil(appDict, sysInfo[@BSG_KSSystemField_BundleID], @"id"); + BSGDictInsertIfNotNil(appDict, configuration.releaseStage, @"releaseStage"); + BSGDictInsertIfNotNil(appDict, sysInfo[@BSG_KSSystemField_SystemName], @"type"); + BSGDictInsertIfNotNil(appDict, sysInfo[@BSG_KSSystemField_BundleShortVersion], @"version"); + + NSMutableDictionary *deviceDict = [NSMutableDictionary new]; + BSGDictInsertIfNotNil(appDict, sysInfo[@BSG_KSSystemField_Jailbroken], @"jailbroken"); + BSGDictInsertIfNotNil(appDict, [[NSLocale currentLocale] localeIdentifier], @"locale"); + BSGDictInsertIfNotNil(appDict, sysInfo[@"Apple"], @"manufacturer"); + BSGDictInsertIfNotNil(appDict, sysInfo[@BSG_KSSystemField_Machine], @"model"); + BSGDictInsertIfNotNil(appDict, sysInfo[@BSG_KSSystemField_Model], @"modelNumber"); + BSGDictInsertIfNotNil(appDict, sysInfo[@BSG_KSSystemField_SystemName], @"osName"); + BSGDictInsertIfNotNil(appDict, sysInfo[@BSG_KSSystemField_SystemVersion], @"osVersion"); + + bugsnagReport.app = appDict; + bugsnagReport.device = deviceDict; } if (![bugsnagReport shouldBeSent])