Skip to content

Commit

Permalink
Merge pull request #250 from rollbar/collect
Browse files Browse the repository at this point in the history
Collect and report all types of crashes together with full stack trace information
  • Loading branch information
matux authored Jan 17, 2023
2 parents 6c641ad + 51148c4 commit 6d3b146
Show file tree
Hide file tree
Showing 24 changed files with 172 additions and 536 deletions.
6 changes: 4 additions & 2 deletions Demos/iosAppObjC/iosAppObjC.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Demos/iosAppSwift/iosAppSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 0 additions & 20 deletions RollbarCommon/Sources/RollbarCommon/RollbarCrashReportData.m

This file was deleted.

4 changes: 3 additions & 1 deletion RollbarCommon/Sources/RollbarCommon/RollbarSdkLog.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

This file was deleted.

45 changes: 0 additions & 45 deletions RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarClient.m

This file was deleted.

7 changes: 3 additions & 4 deletions RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarData.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#import "RollbarRequest.h"
#import "RollbarPerson.h"
#import "RollbarServer.h"
#import "RollbarClient.h"
#import "RollbarModule.h"

#pragma mark - data field keys
Expand Down Expand Up @@ -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];
}

Expand Down
77 changes: 0 additions & 77 deletions RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarJavascript.m

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
102 changes: 75 additions & 27 deletions RollbarNotifier/Sources/RollbarNotifier/RollbarCrashCollector.m
Original file line number Diff line number Diff line change
@@ -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 <KSCrashReportFilter>
@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<RollbarCrashReportData *> *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<KSCrashReportFilter>)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
Loading

0 comments on commit 6d3b146

Please sign in to comment.