diff --git a/Demos/iosAppObjC/iosAppObjC.xcodeproj/project.pbxproj b/Demos/iosAppObjC/iosAppObjC.xcodeproj/project.pbxproj index 3393a739..c14e73b9 100644 --- a/Demos/iosAppObjC/iosAppObjC.xcodeproj/project.pbxproj +++ b/Demos/iosAppObjC/iosAppObjC.xcodeproj/project.pbxproj @@ -320,9 +320,10 @@ CODE_SIGN_ENTITLEMENTS = iosAppObjC/iosAppObjC.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 3; + CURRENT_PROJECT_VERSION = 4; DEVELOPMENT_TEAM = 6B5NER795L; INFOPLIST_FILE = iosAppObjC/Info.plist; + INFOPLIST_KEY_CFBundleDisplayName = "Rollbar ObjC Demo"; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; INFOPLIST_KEY_UIMainStoryboardFile = Main; @@ -349,9 +350,10 @@ CODE_SIGN_ENTITLEMENTS = iosAppObjC/iosAppObjC.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 3; + CURRENT_PROJECT_VERSION = 4; DEVELOPMENT_TEAM = 6B5NER795L; INFOPLIST_FILE = iosAppObjC/Info.plist; + INFOPLIST_KEY_CFBundleDisplayName = "Rollbar ObjC Demo"; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; INFOPLIST_KEY_UIMainStoryboardFile = Main; diff --git a/Demos/iosAppSwift/iosAppSwift.xcodeproj/project.pbxproj b/Demos/iosAppSwift/iosAppSwift.xcodeproj/project.pbxproj index 83281358..712431ca 100644 --- a/Demos/iosAppSwift/iosAppSwift.xcodeproj/project.pbxproj +++ b/Demos/iosAppSwift/iosAppSwift.xcodeproj/project.pbxproj @@ -281,7 +281,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 3; + CURRENT_PROJECT_VERSION = 4; DEVELOPMENT_ASSET_PATHS = "\"iosAppSwift/Preview Content\""; DEVELOPMENT_TEAM = 6B5NER795L; ENABLE_PREVIEWS = YES; @@ -312,7 +312,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 3; + CURRENT_PROJECT_VERSION = 4; DEVELOPMENT_ASSET_PATHS = "\"iosAppSwift/Preview Content\""; DEVELOPMENT_TEAM = 6B5NER795L; ENABLE_PREVIEWS = YES; diff --git a/RollbarCommon/Sources/RollbarCommon/RollbarCrashReportData.m b/RollbarCommon/Sources/RollbarCommon/RollbarCrashReportData.m deleted file mode 100644 index 4ef45d49..00000000 --- a/RollbarCommon/Sources/RollbarCommon/RollbarCrashReportData.m +++ /dev/null @@ -1,20 +0,0 @@ -#import "RollbarCrashReportData.h" - -@implementation RollbarCrashReportData - --(instancetype)initWithCrashReport:(NSString *)report { - - return [self initWithCrashReport:report timestamp:nil]; -} - --(instancetype)initWithCrashReport:(NSString *)report - timestamp:(NSDate *)timestamp { - - if (self = [super init]) { - _crashReport = report; - _timestamp = timestamp; - } - return self; -} - -@end diff --git a/RollbarCommon/Sources/RollbarCommon/RollbarSdkLog.m b/RollbarCommon/Sources/RollbarCommon/RollbarSdkLog.m index 92748b8d..4bb6183f 100644 --- a/RollbarCommon/Sources/RollbarCommon/RollbarSdkLog.m +++ b/RollbarCommon/Sources/RollbarCommon/RollbarSdkLog.m @@ -4,7 +4,9 @@ void RollbarSdkLog(NSString *format, ...) { #ifdef DEBUG va_list args; va_start(args, format); - NSLog(@"[Rollbar] %@", [[NSString alloc] initWithFormat:format arguments:args]); + fprintf( + stderr, "[Rollbar] %s\n", + [[[NSString alloc] initWithFormat:format arguments:args] UTF8String]); va_end(args); #endif } diff --git a/RollbarCommon/Sources/RollbarCommon/include/RollbarCrashReportData.h b/RollbarCommon/Sources/RollbarCommon/include/RollbarCrashReportData.h deleted file mode 100644 index 484985d2..00000000 --- a/RollbarCommon/Sources/RollbarCommon/include/RollbarCrashReportData.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef RollbarCrashReportData_h -#define RollbarCrashReportData_h - -@import Foundation; - -NS_ASSUME_NONNULL_BEGIN - -/// Models crash report data. -@interface RollbarCrashReportData : NSObject - -/// Crash report timestamp. -@property (nonatomic, readonly, nullable) NSDate *timestamp; - -/// Crash report content. -@property (nonatomic, readonly, nonnull) NSString *crashReport; - -/// Crash report data initializer. -/// @param report crash report content. --(instancetype)initWithCrashReport:(nonnull NSString *)report; - -/// Designated crash report data initializer. -/// @param report crash report content. -/// @param timestamp crash report timestamp. --(instancetype)initWithCrashReport:(nonnull NSString *)report - timestamp:(nullable NSDate *)timestamp -NS_DESIGNATED_INITIALIZER; - -/// Hides parameterless initializer. --(instancetype)init -NS_UNAVAILABLE; - -@end - -NS_ASSUME_NONNULL_END - -#endif //RollbarCrashReportData_h diff --git a/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarClient.m b/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarClient.m deleted file mode 100644 index efc351ea..00000000 --- a/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarClient.m +++ /dev/null @@ -1,45 +0,0 @@ -#import "RollbarClient.h" -#import "RollbarJavascript.h" - -#pragma mark - data field keys - -static NSString *const DFK_CPU = @"cpu"; -static NSString *const DFK_JAVASCRIPT = @"javascript"; - -@implementation RollbarClient - -#pragma mark - Properties - --(nullable NSString *)cpu { - return [self getDataByKey:DFK_CPU]; -} - --(void)setCpu:(nullable NSString *)cpu { - [self setData:cpu byKey:DFK_CPU]; -} - --(nullable RollbarJavascript *)javaScript { - id data = [self getDataByKey:DFK_JAVASCRIPT]; - if (data) { - return [[RollbarJavascript alloc] initWithDictionary:data]; - } - return nil; -} - --(void)setJavaScript:(nullable RollbarJavascript *)javaScript { - [self setData:javaScript.jsonFriendlyData byKey:DFK_JAVASCRIPT]; -} - -#pragma mark - Initializers - --(instancetype)initWithCpu:(nullable NSString *)cpu - javaScript:(nullable RollbarJavascript *)javaScript { - - self = [super initWithDictionary:@{ - DFK_CPU: cpu ? cpu: [NSNull null], - DFK_JAVASCRIPT: javaScript ? javaScript.jsonFriendlyData : [NSNull null] - }]; - return self; -} - -@end diff --git a/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarData.m b/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarData.m index 9c0e3d22..e2d1ce4b 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarData.m +++ b/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarData.m @@ -3,7 +3,6 @@ #import "RollbarRequest.h" #import "RollbarPerson.h" #import "RollbarServer.h" -#import "RollbarClient.h" #import "RollbarModule.h" #pragma mark - data field keys @@ -185,15 +184,15 @@ -(void)setServer:(nullable RollbarServer *)value { [self setData:value.jsonFriendlyData byKey:DFK_SERVER]; } --(nullable RollbarClient *)client { +-(nullable RollbarDTO *)client { NSDictionary *data = [self getDataByKey:DFK_CLIENT]; if (data) { - return [[RollbarClient alloc] initWithDictionary:data]; + return [[RollbarDTO alloc] initWithDictionary:data]; } return nil; } --(void)setClient:(nullable RollbarClient *)value { +-(void)setClient:(nullable RollbarDTO *)value { [self setData:value.jsonFriendlyData byKey:DFK_CLIENT]; } diff --git a/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarJavascript.m b/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarJavascript.m deleted file mode 100644 index 6c50ac6d..00000000 --- a/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarJavascript.m +++ /dev/null @@ -1,77 +0,0 @@ -#import "RollbarJavascript.h" - -#pragma mark - data field keys - -static NSString *const DFK_BROWSER = @"browser"; -static NSString *const DFK_CODE_VERSION = @"code_version"; -static NSString *const DFK_SOURCE_MAP_ENABLED = @"source_map_enabled"; -static NSString *const DFK_GUESS_UNCAUGHT_FRAMES = @"guess_uncaught_frames"; - -@implementation RollbarJavascript - -#pragma mark - Properties - --(NSString *)browser { - - NSString *result = [self getDataByKey:DFK_BROWSER]; - return result; -} - --(void)setBrowser:(NSString *)browser { - - [self setData:browser byKey:DFK_BROWSER]; -} - --(NSString *)codeVersion { - - NSString *result = [self getDataByKey:DFK_CODE_VERSION]; - return result; -} - --(void)setCodeVersion:(NSString *)codeVersion { - - [self setData:codeVersion byKey:DFK_CODE_VERSION]; -} - --(RollbarTriStateFlag)sourceMapEnabled { - - NSString *result = [self getDataByKey:DFK_SOURCE_MAP_ENABLED]; - return [RollbarTriStateFlagUtil TriStateFlagFromString:result]; -} - --(void)setSourceMapEnabled:(RollbarTriStateFlag)sourceMapEnabled { - - [self setData:[RollbarTriStateFlagUtil TriStateFlagToString:sourceMapEnabled] - byKey:DFK_SOURCE_MAP_ENABLED]; -} - --(RollbarTriStateFlag)guessUncaughtFrames { - - NSString *result = [self getDataByKey:DFK_GUESS_UNCAUGHT_FRAMES]; - return [RollbarTriStateFlagUtil TriStateFlagFromString:result]; -} - --(void)setGuessUncaughtFrames:(RollbarTriStateFlag)guessUncaughtFrames { - - [self setData:[RollbarTriStateFlagUtil TriStateFlagToString:guessUncaughtFrames] - byKey:DFK_GUESS_UNCAUGHT_FRAMES]; -} - -#pragma mark - Initializers - --(instancetype)initWithBrowser:(nullable NSString *)browser - codeVersion:(nullable NSString *)codeVersion - sourceMapEnabled:(RollbarTriStateFlag)sourceMapEnabled - guessUncaughtFrames:(RollbarTriStateFlag)guessUncaughtFrames { - - self = [super initWithDictionary:@{ - - DFK_BROWSER:browser, - DFK_CODE_VERSION:codeVersion ? codeVersion : [NSNull null], - DFK_SOURCE_MAP_ENABLED:[RollbarTriStateFlagUtil TriStateFlagToString:sourceMapEnabled], - DFK_GUESS_UNCAUGHT_FRAMES:[RollbarTriStateFlagUtil TriStateFlagToString:guessUncaughtFrames] - }]; - return self; -} - -@end diff --git a/RollbarNotifier/Sources/RollbarNotifier/RollbarCrashCollector.h b/RollbarNotifier/Sources/RollbarNotifier/RollbarCrashCollector.h index 2132219c..879c5cb9 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/RollbarCrashCollector.h +++ b/RollbarNotifier/Sources/RollbarNotifier/RollbarCrashCollector.h @@ -3,15 +3,14 @@ @import Foundation; @import RollbarCommon; +@import KSCrash_Installations; NS_ASSUME_NONNULL_BEGIN -/// Rollbar KSCrash reports collector -@interface RollbarCrashCollector: NSObject +/// Rollbar crash report collector +@interface RollbarCrashCollector: KSCrashInstallation -@property (nonatomic, readonly) NSUInteger totalProcessedReports; - -- (void)collectCrashReports; +- (void)sendAllReports; @end diff --git a/RollbarNotifier/Sources/RollbarNotifier/RollbarCrashCollector.m b/RollbarNotifier/Sources/RollbarNotifier/RollbarCrashCollector.m index 1d3a90f9..7828ec55 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/RollbarCrashCollector.m +++ b/RollbarNotifier/Sources/RollbarNotifier/RollbarCrashCollector.m @@ -1,41 +1,89 @@ #import "Rollbar.h" #import "RollbarCrashCollector.h" -#import "RollbarCrashInstallation.h" -#import "RollbarCrashReportData.h" -#import "RollbarCrashReportSink.h" -@implementation RollbarCrashCollector +@import KSCrash_Reporting_Sinks; + +NS_ASSUME_NONNULL_BEGIN -+ (void)initialize { - if (self == [RollbarCrashCollector class]) { - [[RollbarCrashInstallation sharedInstance] install]; +static bool isDebuggerAttached(); + +@interface RollbarCrashReporter : NSObject +@end + +@implementation RollbarCrashReporter + +- (void)filterReports:(NSArray *)reports + onCompletion:(KSCrashReportFilterCompletion)completion +{ + for (NSString *report in reports) { + [Rollbar logCrashReport:report]; } + + kscrash_callCompletion(completion, reports, YES, nil); +} + +@end + +#pragma mark - + +@implementation RollbarCrashCollector + +- (instancetype)init { + return [super initWithRequiredProperties:@[]]; } -- (void)collectCrashReports { - NSMutableArray *crashReports = [[NSMutableArray alloc] init]; - - [[RollbarCrashInstallation sharedInstance] sendAllReportsWithCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { - if (error) { - RollbarSdkLog(@"Could not enable crash reporter: %@", [error localizedDescription]); - } else if (completed) { - for (NSString *crashReport in filteredReports) { - RollbarCrashReportData *crashReportData = [[RollbarCrashReportData alloc] initWithCrashReport:crashReport]; - [crashReports addObject:crashReportData]; - } +- (void)install { + [super install]; + + KSCrashMonitorType monitoring = isDebuggerAttached() + ? KSCrashMonitorTypeDebuggerSafe & ~(KSCrashMonitorTypeOptional | KSCrashMonitorTypeExperimental) + : KSCrashMonitorTypeProductionSafe & ~KSCrashMonitorTypeOptional; + + [KSCrash.sharedInstance setDeleteBehaviorAfterSendAll:KSCDeleteOnSucess]; + [KSCrash.sharedInstance setDemangleLanguages:KSCrashDemangleLanguageAll]; + [KSCrash.sharedInstance setMonitoring:monitoring]; + [KSCrash.sharedInstance setAddConsoleLogToReport:NO]; + [KSCrash.sharedInstance setCatchZombies:NO]; + [KSCrash.sharedInstance setIntrospectMemory:YES]; + [KSCrash.sharedInstance setSearchQueueNames:NO]; +} + +- (void)sendAllReports { + [self sendAllReportsWithCompletion:^(NSArray *_, BOOL completed, NSError *error) { + if (error || !completed) { + RollbarSdkLog(@"Error reporting crash: %@", error); } }]; +} - self->_totalProcessedReports += crashReports.count; +- (id)sink { + id filter = [KSCrashReportFilterAppleFmt filterWithReportStyle:KSAppleReportStyleSymbolicated]; + id report = [[RollbarCrashReporter alloc] init]; + return [KSCrashReportFilterPipeline filterWithFilters:filter, report, nil]; +} - for (RollbarCrashReportData *crashRecord in crashReports) { - [Rollbar logCrashReport:crashRecord.crashReport]; +@end - // Let's sleep this thread for a few seconds to give the items processing thread a chance - // to send the payload logged above so that we can handle cases when the SDK is initialized - // right/shortly before a persistent application crash (that we have no control over) if any: - [NSThread sleepForTimeInterval:5.0f]; // [sec] - } +#pragma mark - + +static bool isDebuggerAttached() { + static bool attached = false; + + static dispatch_once_t token; + dispatch_once(&token, ^{ + struct kinfo_proc info; + size_t info_size = sizeof(info); + int name[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() }; + + if (sysctl(name, 4, &info, &info_size, NULL, 0) == -1) { + RollbarSdkLog(@"Error checking for debugger via sysctl(): %s", strerror(errno)); + } else if (info.kp_proc.p_flag & P_TRACED) { + RollbarSdkLog(@"Found a debugger attached"); + attached = true; + } + }); + + return attached; } -@end +NS_ASSUME_NONNULL_END diff --git a/RollbarNotifier/Sources/RollbarNotifier/RollbarCrashInstallation.h b/RollbarNotifier/Sources/RollbarNotifier/RollbarCrashInstallation.h deleted file mode 100644 index 9395976e..00000000 --- a/RollbarNotifier/Sources/RollbarNotifier/RollbarCrashInstallation.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef RollbarCrashInstallation_h -#define RollbarCrashInstallation_h - -@import KSCrash_Installations; - -NS_ASSUME_NONNULL_BEGIN - -/// Rollbar Crash installation helper -@interface RollbarCrashInstallation : KSCrashInstallation - -/// The shared instance of this helper. -+ (instancetype)sharedInstance; - -@end - -NS_ASSUME_NONNULL_END - -#endif //RollbarCrashInstallation_h diff --git a/RollbarNotifier/Sources/RollbarNotifier/RollbarCrashInstallation.m b/RollbarNotifier/Sources/RollbarNotifier/RollbarCrashInstallation.m deleted file mode 100644 index bcb81123..00000000 --- a/RollbarNotifier/Sources/RollbarNotifier/RollbarCrashInstallation.m +++ /dev/null @@ -1,33 +0,0 @@ -#import "RollbarCrashInstallation.h" -#import "RollbarCrashReportSink.h" - -@implementation RollbarCrashInstallation - -+ (instancetype)sharedInstance { - static RollbarCrashInstallation *sharedInstance = nil; - static dispatch_once_t onceToken; - - dispatch_once(&onceToken, ^{ - sharedInstance = [[RollbarCrashInstallation alloc] init]; - }); - - return sharedInstance; -} - -- (id)init { - return [super initWithRequiredProperties:@[]]; -} - -- (id)sink { - return [[[RollbarCrashReportSink alloc] init] defaultFilterSet]; -} - -- (void)sendAllReportsWithCompletion:(KSCrashReportFilterCompletion)onCompletion { - [super sendAllReportsWithCompletion:^(NSArray *filteredReports, BOOL completed, NSError *error) { - if (completed && onCompletion) { - onCompletion(filteredReports, completed, error); - } - }]; -} - -@end diff --git a/RollbarNotifier/Sources/RollbarNotifier/RollbarCrashReportSink.h b/RollbarNotifier/Sources/RollbarNotifier/RollbarCrashReportSink.h deleted file mode 100644 index d3acfecb..00000000 --- a/RollbarNotifier/Sources/RollbarNotifier/RollbarCrashReportSink.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef RollbarCrashReportSink_h -#define RollbarCrashReportSink_h - -@import Foundation; -@import KSCrash_Reporting_Sinks; - -NS_ASSUME_NONNULL_BEGIN - -/// Rollbar CrashReport sink -@interface RollbarCrashReportSink : NSObject - -/// Gets the default filter set -- (id)defaultFilterSet; - -@end - -NS_ASSUME_NONNULL_END - -#endif //RollbarCrashReportSink_h diff --git a/RollbarNotifier/Sources/RollbarNotifier/RollbarCrashReportSink.m b/RollbarNotifier/Sources/RollbarNotifier/RollbarCrashReportSink.m deleted file mode 100644 index e483431a..00000000 --- a/RollbarNotifier/Sources/RollbarNotifier/RollbarCrashReportSink.m +++ /dev/null @@ -1,18 +0,0 @@ -#import "RollbarCrashReportSink.h" - -@implementation RollbarCrashReportSink - -- (id)defaultFilterSet { - KSCrashReportFilterAppleFmt *format = [KSCrashReportFilterAppleFmt filterWithReportStyle:KSAppleReportStyleSymbolicated]; - KSCrashReportFilterPipeline *pipeline = [KSCrashReportFilterPipeline filterWithFilters:format, self, nil]; - return pipeline; -} - -- (void)filterReports:(NSArray *)reports onCompletion:(KSCrashReportFilterCompletion)onCompletion { - for (NSString *report in reports) { - //[Rollbar logCrashReport:report]; - } - kscrash_callCompletion(onCompletion, reports, YES, nil); -} - -@end diff --git a/RollbarNotifier/Sources/RollbarNotifier/RollbarInfrastructure.m b/RollbarNotifier/Sources/RollbarNotifier/RollbarInfrastructure.m index f1822f94..c33c065d 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/RollbarInfrastructure.m +++ b/RollbarNotifier/Sources/RollbarNotifier/RollbarInfrastructure.m @@ -42,14 +42,13 @@ - (nonnull instancetype)configureWith:(nonnull RollbarConfig *)config { self.configuration = [config copy]; self.logger = [RollbarLogger loggerWithConfiguration:self.configuration]; - self.collector = [[RollbarCrashCollector alloc] init]; - [self.collector collectCrashReports]; - [[RollbarTelemetry sharedInstance] configureWithOptions:config.telemetry]; - RollbarSdkLog(@"%@ is configured with this RollbarConfig instance: \n%@", - [RollbarInfrastructure rollbar_objectClassName], - config); + self.collector = [[RollbarCrashCollector alloc] init]; + [self.collector install]; + [self.collector sendAllReports]; + + RollbarSdkLog(@"%@ started", [RollbarInfrastructure rollbar_objectClassName]); return self; } diff --git a/RollbarNotifier/Sources/RollbarNotifier/RollbarPayloadFactory.m b/RollbarNotifier/Sources/RollbarNotifier/RollbarPayloadFactory.m index 551f9812..439e0c37 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/RollbarPayloadFactory.m +++ b/RollbarNotifier/Sources/RollbarNotifier/RollbarPayloadFactory.m @@ -11,7 +11,6 @@ #import "RollbarData.h" #import "RollbarPerson.h" #import "RollbarServer.h" -#import "RollbarClient.h" #import "RollbarModule.h" #import @@ -20,11 +19,15 @@ @import UIKit; #endif +@interface RollbarPayloadFactory () + +@property (strong) NSMutableDictionary *osData; + +@end + @implementation RollbarPayloadFactory { - - @private +@private RollbarConfig *_config; // expected to be nonnull... - NSMutableDictionary *_osData; } + (instancetype)factoryWithConfig:(nonnull RollbarConfig *)config { @@ -158,14 +161,12 @@ -(nullable RollbarPayload *)buildRollbarPayloadWithLevel:(RollbarLevel)level return nil; } - NSMutableDictionary *customData = - [NSMutableDictionary dictionaryWithDictionary:self->_config.customData]; - if (crashReport || exception) { - // neither crash report no exception payload objects have placeholders for any extra data - // or an extra message, let's preserve them as the custom data: + NSMutableDictionary *customData = [NSMutableDictionary dictionaryWithDictionary:self->_config.customData]; + if (exception) { if (extra) { customData[@"error.extra"] = extra.mutableCopy; } + if (message && message.length > 0) { customData[@"error.message"] = message; } @@ -211,20 +212,20 @@ -(RollbarModule *)buildRollbarNotifierModule { return nil; } --(RollbarClient *)buildRollbarClient { +-(RollbarDTO *)buildRollbarClient { NSNumber *timestamp = [NSNumber numberWithInteger:[[NSDate date] timeIntervalSince1970]]; if (self->_config.loggingOptions) { - switch(self->_config.loggingOptions.captureIp) { + switch (self->_config.loggingOptions.captureIp) { case RollbarCaptureIpType_Full: - return [[RollbarClient alloc] initWithDictionary:@{ + return [[RollbarDTO alloc] initWithDictionary:@{ @"timestamp": timestamp, @"ios": [self buildOSData], @"user_ip": @"$remote_ip" }]; case RollbarCaptureIpType_Anonymize: - return [[RollbarClient alloc] initWithDictionary:@{ + return [[RollbarDTO alloc] initWithDictionary:@{ @"timestamp": timestamp, @"ios": [self buildOSData], @"user_ip": @"$remote_ip_anonymize" @@ -235,7 +236,7 @@ -(RollbarClient *)buildRollbarClient { } } - return [[RollbarClient alloc] initWithDictionary:@{ + return [[RollbarDTO alloc] initWithDictionary:@{ @"timestamp": timestamp, @"ios": [self buildOSData], }]; @@ -262,64 +263,45 @@ -(RollbarServer *)buildRollbarServer { } } --(NSDictionary *)buildOSData { - - //TODO: redo this implementation based on the helper utils used by RollbarSession or on RollbarSession itself... - - if (self->_osData) { - return self->_osData; +- (NSDictionary *)buildOSData { + if (self.osData) { + return self.osData; } - + NSBundle *mainBundle = [NSBundle mainBundle]; - - NSString *version = nil; - if (self->_config.loggingOptions - && self->_config.loggingOptions.codeVersion - && self->_config.loggingOptions.codeVersion.length > 0) { - - version = self->_config.loggingOptions.codeVersion; - } - else { - version = [mainBundle objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey]; - } - + NSString *codeVersion = [mainBundle objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey]; NSString *shortVersion = [mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; NSString *bundleName = [mainBundle objectForInfoDictionaryKey:(NSString *)kCFBundleNameKey]; NSString *bundleIdentifier = [mainBundle objectForInfoDictionaryKey:(NSString *)kCFBundleIdentifierKey]; - + struct utsname systemInfo; uname(&systemInfo); - NSString *deviceCode = [NSString stringWithCString:systemInfo.machine - encoding:NSUTF8StringEncoding]; - + NSString *deviceCode = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding]; + #if TARGET_OS_IOS | TARGET_OS_TV | TARGET_OS_MACCATALYST - self->_osData = @{ + self.osData = @{ @"os": @"iOS", @"os_version": [[UIDevice currentDevice] systemVersion], @"device_code": deviceCode, - @"code_version": version ? version : @"", - @"short_version": shortVersion ? shortVersion : @"", - @"bundle_identifier": bundleIdentifier ? bundleIdentifier : @"", - @"app_name": bundleName ? bundleName : @"" + @"code_version": codeVersion ?: @"", + @"short_version": shortVersion ?: @"", + @"bundle_identifier": bundleIdentifier ?: @"", + @"app_name": bundleName ?: @"" }.mutableCopy; #else - NSOperatingSystemVersion osVer = [[NSProcessInfo processInfo] operatingSystemVersion]; - self->_osData = @{ + NSOperatingSystemVersion v = [[NSProcessInfo processInfo] operatingSystemVersion]; + self.osData = @{ @"os": @"macOS", - @"os_version": [NSString stringWithFormat:@" %tu.%tu.%tu", - osVer.majorVersion, - osVer.minorVersion, - osVer.patchVersion - ], + @"os_version": [NSString stringWithFormat:@" %tu.%tu.%tu", v.majorVersion, v.minorVersion, v.patchVersion], @"device_code": deviceCode, - @"code_version": version ? version : @"", - @"short_version": shortVersion ? shortVersion : @"", - @"bundle_identifier": bundleIdentifier ? bundleIdentifier : @"", - @"app_name": bundleName ? bundleName : [[NSProcessInfo processInfo] processName] + @"code_version": version ?: @"", + @"short_version": shortVersion ?: @"", + @"bundle_identifier": bundleIdentifier ?: @"", + @"app_name": bundleName ?: [[NSProcessInfo processInfo] processName] }.mutableCopy; #endif - return self->_osData; + return self.osData; } @end diff --git a/RollbarNotifier/Sources/RollbarNotifier/RollbarPayloadRepository.m b/RollbarNotifier/Sources/RollbarNotifier/RollbarPayloadRepository.m index c1192fa7..49869780 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/RollbarPayloadRepository.m +++ b/RollbarNotifier/Sources/RollbarNotifier/RollbarPayloadRepository.m @@ -15,11 +15,11 @@ static int defaultOnSelectCallback(void *info, int columns, char **data, char **column) { - RollbarSdkLog(@"Columns: %d", columns); - for (int i = 0; i < columns; i++) { - RollbarSdkLog(@"Column: %s", column[i]); - RollbarSdkLog(@"Data: %s", data[i]); - } +// RollbarSdkLog(@"Columns: %d", columns); +// for (int i = 0; i < columns; i++) { +// RollbarSdkLog(@"Column: %s", column[i]); +// RollbarSdkLog(@"Data: %s", data[i]); +// } return SQLITE_OK; } diff --git a/RollbarNotifier/Sources/RollbarNotifier/RollbarSender.m b/RollbarNotifier/Sources/RollbarNotifier/RollbarSender.m index 8b209ab9..8e2cb40c 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/RollbarSender.m +++ b/RollbarNotifier/Sources/RollbarNotifier/RollbarSender.m @@ -30,39 +30,30 @@ + (void)assertError:(nonnull NSString *)error } - (nullable RollbarPayloadPostReply *)sendPayload:(nonnull NSData *)payload - usingConfig:(nonnull RollbarConfig *)config { + usingConfig:(nonnull RollbarConfig *)config +{ + RollbarPayloadPostReply *reply; - RollbarPayloadPostReply *reply = nil; - - if (YES == config.developerOptions.transmit) { + if (config.developerOptions.transmit) { reply = [self transmitPayload:payload toDestination:config.destination usingDeveloperOptions:config.developerOptions andHttpProxySettings:config.httpProxy - andHttpsProxySettings:config.httpsProxy - ]; - } - else { + andHttpsProxySettings:config.httpsProxy]; + } else { reply = [RollbarPayloadPostReply greenReply]; // we just successfully short-circuit here... } - NSString *payloadString = [[NSString alloc] initWithData:payload - encoding:NSUTF8StringEncoding]; - if (reply && (200 == reply.statusCode)) { - [RollbarSender trace:[NSString stringWithFormat:@"Transmitted payload: %@", payloadString] - withOptions:config.developerOptions]; -// if ((YES == config.developerOptions.logTransmittedPayloads) && config.developerOptions.transmittedPayloadLogFile) { -// [RollbarFileWriter appendSafelyData:payload toFile:config.developerOptions.transmittedPayloadLogFile]; -// //TODO: complete implementation (log into payloads log file)... -// } - } - else if (reply) { - [RollbarSender trace:[NSString stringWithFormat:@"Failed to transmit payload (%li status code): %@", (long)reply.statusCode, payloadString] - withOptions:config.developerOptions]; - } - else { - [RollbarSender trace:[NSString stringWithFormat:@"Failed to transmit payload (no reply): %@", payloadString] - withOptions:config.developerOptions]; + NSString *payloadString = [[NSString alloc] initWithData:payload encoding:NSUTF8StringEncoding]; + + if (reply && reply.statusCode == 200) { + NSUInteger truncateIndex = MIN(payloadString.length, 256); + NSString *truncatedString = [payloadString substringToIndex:truncateIndex]; + [RollbarSender trace:[NSString stringWithFormat:@"Transmitted payload: %@...", truncatedString] withOptions:config.developerOptions]; + } else if (reply) { + [RollbarSender trace:[NSString stringWithFormat:@"Failed to transmit payload (%li status code): %@", (long)reply.statusCode, payloadString] withOptions:config.developerOptions]; + } else { + [RollbarSender trace:[NSString stringWithFormat:@"Failed to transmit payload (no reply): %@", payloadString] withOptions:config.developerOptions]; } return reply; @@ -177,35 +168,23 @@ - (nullable NSHTTPURLResponse *)postPayload:(nonnull NSData *)payload - (nullable NSHTTPURLResponse *)checkPayloadResponse:(NSURLResponse *)response error:(NSError *)error data:(NSData *)data - usingDeveloperOptions:(nonnull RollbarDeveloperOptions *)developerOptions { - + usingDeveloperOptions:(nonnull RollbarDeveloperOptions *)developerOptions +{ if (error) { - [RollbarSender trace:@"There was an error reporting to Rollbar:" - withOptions:developerOptions]; - [RollbarSender trace:[NSString stringWithFormat:@" Error: %@", [error localizedDescription]] - withOptions:developerOptions]; + [RollbarSender trace:@"There was an error reporting to Rollbar:" withOptions:developerOptions]; + [RollbarSender trace:[NSString stringWithFormat:@" Error: %@", [error localizedDescription]] withOptions:developerOptions]; return nil; } - NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response; - if (httpResponse && (200 == [httpResponse statusCode])) { - [RollbarSender trace:[NSString stringWithFormat:@"OK response from Rollar: %@", httpResponse] - withOptions:developerOptions]; + NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; + if (httpResponse && [httpResponse statusCode] == 200) { + [RollbarSender trace:[NSString stringWithFormat:@"OK response from Rollar: %ld", [httpResponse statusCode]] withOptions:developerOptions]; return httpResponse; } - [RollbarSender trace:@"There was a problem reporting to Rollbar:" - withOptions:developerOptions]; - [RollbarSender trace:[NSString stringWithFormat:@" Response: %@", response] - withOptions:developerOptions]; - [RollbarSender trace:[NSString stringWithFormat:@" Response data: %@", data] - withOptions:developerOptions]; - // [RollbarSender trace:[NSString stringWithFormat:@" Response data: %@", - // [NSJSONSerialization JSONObjectWithData:data - // options:0 - // error:nil] - // ] - // withOptions:developerOptions]; + [RollbarSender trace:@"There was a problem reporting to Rollbar:" withOptions:developerOptions]; + [RollbarSender trace:[NSString stringWithFormat:@" Response: %@", response] withOptions:developerOptions]; + [RollbarSender trace:[NSString stringWithFormat:@" Response data: %@", data] withOptions:developerOptions]; return nil; } diff --git a/RollbarNotifier/Sources/RollbarNotifier/RollbarThread.m b/RollbarNotifier/Sources/RollbarNotifier/RollbarThread.m index 8b7f329b..6e171911 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/RollbarThread.m +++ b/RollbarNotifier/Sources/RollbarNotifier/RollbarThread.m @@ -294,7 +294,7 @@ - (void)queuePayload_OnlyCallOnThisThread:(nonnull NSArray *)data { } - (void)savePayload:(nonnull RollbarPayload *)payload withConfig:(nonnull RollbarConfig *)config { - + //RollbarSdkLog(@"RollbarThread::savePayload: %@", payload.data.body); if ([RollbarThread shouldIgnorePayload:payload withConfig:config]) { @@ -311,8 +311,7 @@ - (void)savePayload:(nonnull RollbarPayload *)payload withConfig:(nonnull Rollba if (!config.developerOptions.suppressSdkInfoLogging) { RollbarSdkLog(@"Dropped payload (due to checkIgnore): %@", [[NSString alloc] initWithData:[payload serializeToJSONData] - encoding:NSUTF8StringEncoding] - ); + encoding:NSUTF8StringEncoding]); } return; } @@ -333,8 +332,7 @@ - (void)savePayload:(nonnull RollbarPayload *)payload withConfig:(nonnull Rollba if (!config.developerOptions.suppressSdkInfoLogging) { RollbarSdkLog(@"Dropped payload (due to modifyPayload failure): %@", [[NSString alloc] initWithData:[payload serializeToJSONData] - encoding:NSUTF8StringEncoding] - ); + encoding:NSUTF8StringEncoding]); } return; } @@ -355,8 +353,7 @@ - (void)savePayload:(nonnull RollbarPayload *)payload withConfig:(nonnull Rollba if (!config.developerOptions.suppressSdkInfoLogging) { RollbarSdkLog(@"Dropped payload (due to scrubPayload failure): %@", [[NSString alloc] initWithData:[payload serializeToJSONData] - encoding:NSUTF8StringEncoding] - ); + encoding:NSUTF8StringEncoding]); } return; } @@ -553,20 +550,18 @@ - (void)processSavedPayload:(nonnull NSDictionary *)payl NSString *payloadsLogFilePath = [cachesDirectory stringByAppendingPathComponent:payloadsLogFile]; [RollbarFileWriter appendSafelyData:jsonPayload toFile:payloadsLogFilePath]; } + if (!config.developerOptions.suppressSdkInfoLogging) { NSString *sdkLogTrace = nil; switch(success) { case RollbarTriStateFlag_On: - RollbarSdkLog(@"Transmitted payload: %@", - [[NSString alloc] initWithData:jsonPayload encoding:NSUTF8StringEncoding]); + //RollbarSdkLog(@"Transmitted payload: %@", [[NSString alloc] initWithData:jsonPayload encoding:NSUTF8StringEncoding]); break; case RollbarTriStateFlag_Off: - RollbarSdkLog(@"Dropped payload: %@", - [[NSString alloc] initWithData:jsonPayload encoding:NSUTF8StringEncoding]); + RollbarSdkLog(@"Dropped payload: %@", [[NSString alloc] initWithData:jsonPayload encoding:NSUTF8StringEncoding]); break; case RollbarTriStateFlag_None: - RollbarSdkLog(@"Couldn't transmit (and will try) payload: %@", - [[NSString alloc] initWithData:jsonPayload encoding:NSUTF8StringEncoding]); + RollbarSdkLog(@"Couldn't transmit (and will try) payload: %@", [[NSString alloc] initWithData:jsonPayload encoding:NSUTF8StringEncoding]); break; } } diff --git a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarClient.h b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarClient.h deleted file mode 100644 index 16a4224a..00000000 --- a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarClient.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef RollbarClient_h -#define RollbarClient_h - -@import RollbarCommon; - -@class RollbarJavascript; - -NS_ASSUME_NONNULL_BEGIN - -/// RollbarClient payload element -/// -/// @note: -/// Can contain any arbitrary keys. Rollbar understands the following: -@interface RollbarClient : RollbarDTO - -#pragma mark - Properties - -/// Optional: cpu -/// A string up to 255 characters -@property (nonatomic, copy, nullable) NSString *cpu; - -/// javaScript -@property (nonatomic, strong, nullable) RollbarJavascript *javaScript; - -#pragma mark - Initializers - -/// Initializer -/// @param cpu CPU -/// @param javaScript javaScript --(instancetype)initWithCpu:(nullable NSString *)cpu - javaScript:(nullable RollbarJavascript *)javaScript; - -@end - -NS_ASSUME_NONNULL_END - -#endif //RollbarClient_h diff --git a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarData.h b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarData.h index c3244a65..d29c890e 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarData.h +++ b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarData.h @@ -94,7 +94,7 @@ NS_ASSUME_NONNULL_BEGIN /// Data about the client device this event occurred on. /// As there can be multiple client environments for a given event (i.e. Flash running inside /// an HTML page), data should be namespaced by platform. -@property (nonatomic, nullable) RollbarClient *client; +@property (nonatomic, nullable) RollbarDTO *client; /// Optional: custom /// Any arbitrary metadata you want to send. "custom" itself should be an object. diff --git a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarJavascript.h b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarJavascript.h deleted file mode 100644 index 3fa0bf0d..00000000 --- a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarJavascript.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef RollbarJavascript_h -#define RollbarJavascript_h - -@import RollbarCommon; - -NS_ASSUME_NONNULL_BEGIN - -/// JavaScript data element of a payload -@interface RollbarJavascript : RollbarDTO - -#pragma mark - Properties - -/// Optional: browser -/// The user agent string -@property (nonatomic, nullable, copy) NSString *browser; - -/// Optional: code_version -/// String describing the running code version in javascript -/// See note about "code_version" above -@property (nonatomic, nullable, copy) NSString *codeVersion; - -/// Optional: source_map_enabled -/// Set to true to enable source map deobfuscation -/// See the "Source Maps" guide for more details. -@property (nonatomic) RollbarTriStateFlag sourceMapEnabled; - -/// Optional: guess_uncaught_frames -/// Set to true to enable frame guessing -/// See the "Source Maps" guide for more details. -@property (nonatomic) RollbarTriStateFlag guessUncaughtFrames; - -#pragma mark - Initializers - -/// Initializer -/// @param browser browser description -/// @param codeVersion code version -/// @param sourceMapEnabled source maps enabled flag -/// @param guessUncaughtFrames a flag to guess uncaught exceptions --(instancetype)initWithBrowser:(nullable NSString *)browser - codeVersion:(nullable NSString *)codeVersion - sourceMapEnabled:(RollbarTriStateFlag)sourceMapEnabled - guessUncaughtFrames:(RollbarTriStateFlag)guessUncaughtFrames; - -@end - -NS_ASSUME_NONNULL_END - -#endif //RollbarJavascript_h diff --git a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarLoggingOptions.h b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarLoggingOptions.h index ce1ba2ae..4fd347a1 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarLoggingOptions.h +++ b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarLoggingOptions.h @@ -51,22 +51,6 @@ NS_ASSUME_NONNULL_BEGIN framework:(nullable NSString *)framework requestId:(nullable NSString *)requestId; -/// Initializer -/// @param logLevel minimum log level to start logging from -/// @param crashLevel log level to mark crash reports with -/// @param maximumReportsPerMinute Reporting rate limit -/// @param captureIp a way of capturing IP addresses -/// @param codeVersion a code version to mark payloads with -/// @param framework A framework tag to mark payloads with -/// @param requestId A request ID to mark payloads with -- (instancetype)initWithLogLevel:(RollbarLevel)logLevel - crashLevel:(RollbarLevel)crashLevel - maximumReportsPerMinute:(NSUInteger)maximumReportsPerMinute - captureIp:(RollbarCaptureIpType)captureIp - codeVersion:(nullable NSString *)codeVersion - framework:(nullable NSString *)framework - requestId:(nullable NSString *)requestId; - /// Initializer /// @param logLevel minimum log level to start logging from /// @param crashLevel log level to mark crash reports with diff --git a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarPayloadDTOs.h b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarPayloadDTOs.h index b31382e4..b55a09ad 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarPayloadDTOs.h +++ b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarPayloadDTOs.h @@ -29,8 +29,6 @@ #import "RollbarTelemetryOptions.h" #import "RollbarLoggingOptions.h" #import "RollbarServer.h" -#import "RollbarClient.h" -#import "RollbarJavascript.h" #import "RollbarTelemetryType.h" #import "RollbarTelemetryEvent.h"