-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #250 from rollbar/collect
Collect and report all types of crashes together with full stack trace information
- Loading branch information
Showing
24 changed files
with
172 additions
and
536 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
RollbarCommon/Sources/RollbarCommon/RollbarCrashReportData.m
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
RollbarCommon/Sources/RollbarCommon/include/RollbarCrashReportData.h
This file was deleted.
Oops, something went wrong.
45 changes: 0 additions & 45 deletions
45
RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarClient.m
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 0 additions & 77 deletions
77
RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarJavascript.m
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 75 additions & 27 deletions
102
RollbarNotifier/Sources/RollbarNotifier/RollbarCrashCollector.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.