Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add screenshot at crash #1920

Merged
merged 33 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4ba0322
SentryCrash screenshot callback
brustolin Jun 22, 2022
9494db5
add screenshot attachment
brustolin Jun 27, 2022
cc44cca
Merge branch 'master' into feat/crash-screenshot
brustolin Jun 27, 2022
aca1443
Format code
getsentry-bot Jun 27, 2022
a4bad19
Update CHANGELOG.md
brustolin Jun 27, 2022
8c5465c
Merge branch 'feat/crash-screenshot' of https://github.com/getsentry/…
brustolin Jun 27, 2022
66820bc
Apply suggestions from code review
brustolin Jun 28, 2022
23d3536
Improvements with file interactions
brustolin Jun 28, 2022
ae6b9e0
Merge branch 'master' into feat/crash-screenshot
brustolin Jun 28, 2022
d60054c
string format
brustolin Jun 28, 2022
4eadd21
Format code
getsentry-bot Jun 28, 2022
dcfb4f9
Merge branch 'master' into feat/crash-screenshot
brustolin Jun 29, 2022
7f66d8d
Merge branch 'feat/crash-screenshot' of https://github.com/getsentry/…
brustolin Jun 29, 2022
a723c7a
Report sink test
brustolin Jun 29, 2022
636bcbe
integration test
brustolin Jun 30, 2022
511864a
Update SentryScreenshot.m
brustolin Jun 30, 2022
db0865e
Merge branch 'master' into feat/crash-screenshot
brustolin Jun 30, 2022
e2fa1f2
tests
brustolin Jul 1, 2022
ceb5fbe
Format code
getsentry-bot Jul 1, 2022
453dddf
Update SentryCrash.m
brustolin Jul 1, 2022
cbe448f
Merge branch 'feat/crash-screenshot' of https://github.com/getsentry/…
brustolin Jul 1, 2022
60a7c2e
Update SentryCrashReportStore.c
brustolin Jul 1, 2022
5229655
Format code
getsentry-bot Jul 1, 2022
da48b93
Apply suggestions from code review
brustolin Jul 6, 2022
dbf5d0b
testfs
brustolin Jul 6, 2022
bd84076
Merge branch 'feat/crash-screenshot' of https://github.com/getsentry/…
brustolin Jul 6, 2022
64845d0
Update SentryCrash.m
brustolin Jul 6, 2022
6a66e78
Format code
getsentry-bot Jul 6, 2022
0b5531a
Update SentryCrashReportStore_Tests.m
brustolin Jul 6, 2022
9b880f6
Format code
getsentry-bot Jul 6, 2022
8c66ac8
more fixes
brustolin Jul 6, 2022
068179d
Merge branch 'feat/crash-screenshot' of https://github.com/getsentry/…
brustolin Jul 6, 2022
bf6008e
Merge branch 'master' into feat/crash-screenshot
brustolin Jul 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Sentry/SentryScreenshot.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ - (void)saveScreenShots:(NSString *)path
{
// This function does not dispatch the screenshot to the main thread.
// The caller should be aware of that.
// We done this way because we use this function to save screenshots
// We did it this way because we use this function to save screenshots
// during signal handling, and if we dispatch it to the main thread,
// that is probably blocked by the crash event, we freeze the application.
[[self takeScreenshots] enumerateObjectsUsingBlock:^(NSData *obj, NSUInteger idx, BOOL *stop) {
Expand Down
19 changes: 10 additions & 9 deletions Sources/Sentry/SentryScreenshotIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@
error:&error];
if (error != nil)
return;
}

// We first delete any screenshot that could be from an old crash report
NSArray *oldFiles = [NSFileManager.defaultManager contentsOfDirectoryAtPath:reportPath
error:&error];
if (!error) {
[oldFiles enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL *stop) {
[NSFileManager.defaultManager removeItemAtPath:obj error:nil];
}];
} else {
// We first delete any screenshot that could be from an old crash report
NSArray *oldFiles = [NSFileManager.defaultManager contentsOfDirectoryAtPath:reportPath
error:&error];

if (!error) {
[oldFiles enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL *stop) {
[NSFileManager.defaultManager removeItemAtPath:obj error:nil];
}];
}
}

[SentryDependencyContainer.sharedInstance.screenshot saveScreenShots:reportPath];
Expand Down
6 changes: 3 additions & 3 deletions Sources/SentryCrash/Recording/SentryCrash.m
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ - (NSData *)loadCrashReportJSONWithID:(int64_t)reportID
return nil;
}

- (NSArray *)getScreenShots:(int64_t)reportID
- (NSArray<NSString *> *)getScreenshotPaths:(int64_t)reportID
brustolin marked this conversation as resolved.
Show resolved Hide resolved
{
char report_screenshot_path[SentryCrashCRS_MAX_PATH_LENGTH];
sentrycrashcrs_getScreenshotPath_forReportId(reportID, report_screenshot_path);
Expand Down Expand Up @@ -485,9 +485,9 @@ - (NSDictionary *)reportWithIntID:(int64_t)reportID
return nil;
}

NSArray *screenShots = [self getScreenShots:reportID];
NSArray *screenShots = [self getScreenshotPaths:reportID];
if (screenShots.count > 0) {
[crashReport setObject:screenShots forKey:SENTRYCRASH_REPORT_SCREENSHOT_ITEM];
crashReport[SENTRYCRASH_REPORT_SCREENSHOT_ITEM] = screenShots;
}

[self doctorReport:crashReport];
Expand Down
2 changes: 1 addition & 1 deletion Sources/SentryCrash/Recording/SentryCrashC.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ onCrash(struct SentryCrash_MonitorContext *monitorContext)
// Depending on the state of the crash this may not work
// because we gonna call into non async-signal safe code
// but since the app is already in a crash state we don't
// mind if this approach causes more crashes.
// mind if this approach crashes.
if (g_saveScreenShot) {
char crashScreenshotsPath[SentryCrashFU_MAX_PATH_LENGTH];
sentrycrashcrs_getScreenshotsPath_forReport(
Expand Down
3 changes: 1 addition & 2 deletions Tests/SentryTests/SentryCrash/SentryCrashTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ - (void)test_getScreenshots_CheckName
initWithBasePath:[self.tempPath stringByAppendingPathComponent:@"Reports"]];
NSArray *files = [sentryCrash getScreenShots:12];

XCTAssertEqual(files.count, 1);
XCTAssertEqualObjects(files.firstObject,
[self.tempPath stringByAppendingPathComponent:
@"Reports/AppName-report-000000000000000c-screenshots/0.png"]);

XCTAssertEqual(files.count, 1);
}

- (void)test_getScreenshots_TwoFiles
Expand Down