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

Log messages/crashes in CoreDataManager in Storage framework #2366

Merged
merged 14 commits into from
Jun 3, 2020

Conversation

jaclync
Copy link
Contributor

@jaclync jaclync commented May 29, 2020

Fixes #2364

Background

Since only WooCommerce framework knows about AutomatticTracks framework and thus the CrashLogging helper is only accessible within WooCommerce. However, there are also cases we'd like to log crashes/messages in frameworks other than WooCommerce like Storage and Yosemite frameworks for any potential crashes (ref p91TBi-2PM-p2). This PR created a protocol for WooCommerce to implement with AutomatticTracks's CrashLogging via Sentry, and pass this implementation to CoreDataManager as a start.

Changes

  • Created a CrashLogger protocol in the Storage framework that allows logging a message of any severity level
    • The naming is just following the implementation CrashLogging in AutomatticTracks, please lemme know if you think some other name would be more clear
  • Added CrashLogger dependency to CoreDataManager
  • Created SentryCrashLogger to implement CrashLogger with AutomatticTracks's CrashLogging, and passed this implementation to CoreDataManager in ServiceLocator
  • Separated copying and removing the old persistent store so that we have more insight about where the error comes from fatalError (in case we can't get logging from Sentry)
  • Updated unit tests in Storage and Yosemite with MockCrashLogger mock

Testing

You can try putting a similar call to CrashLogger in CoreDataManager's loadPersistentStores' success block followed by a fatalError, then build with "Release-Alpha" configuration, and check on Sentry for the event.

Update release notes:

  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@jaclync jaclync added the type: crash The worst kind of bug. label May 29, 2020
@jaclync jaclync added this to the 4.4 milestone May 29, 2020
@jaclync jaclync requested a review from a team May 29, 2020 06:52
@jaclync jaclync self-assigned this May 29, 2020
@peril-woocommerce
Copy link

peril-woocommerce bot commented May 29, 2020

You can trigger an installable build for these changes by visiting CircleCI here.

@peril-woocommerce
Copy link

peril-woocommerce bot commented May 29, 2020

You can trigger optional UI/connected tests for these changes by visiting CircleCI here.

…e more insight about where the error comes from.
Copy link
Member

@pmusolino pmusolino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

I really hope this will help us to investigate better all the crashes in Storage 💯

fatalError(message)
}

/// Remove the old Store
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea to separate the removeItem: from the copyItem: 👍

@shiki
Copy link
Member

shiki commented May 29, 2020

Related to #2371

Copy link
Member

@shiki shiki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, @jaclync! Thanks for working on this. 🙇

I have not fully tested this yet. I still have to do the installable build route. I'm submitting this review since there's one thing that I think needs your attention (marked with ⚠️ ).

@jaclync
Copy link
Contributor Author

jaclync commented Jun 1, 2020

👋 Platform 9 @oguzkocer @loremattei since we'd like to understand more about one of the top crashes in WCiOS (p91TBi-2PM-p2) that isn't currently logged on Sentry yet, it'd be great if this PR can be merged to release 4.4 when it's ready!

@jaclync
Copy link
Contributor Author

jaclync commented Jun 1, 2020

@shiki thanks so much for catching the JSON serialization issue! that was the reason why the test events weren't logged to Sentry before. I responded to your comments for another pass 😄

Copy link
Member

@shiki shiki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, @jaclync! Thanks for the changes. I was finally able to test this in Sentry.

I have a few additional comments.

Unrecoverable Crash

I'd like to double-check this with you. I tested the crash by adding using this in lazy var persistentContainer:

        container.loadPersistentStores { [weak self] (storeDescription, error) in
            guard let self = self else {
                return
            }
            let persistentStoreLoadingError = NSError(domain: "test by shiki", code: 9_999, userInfo: nil)

I used WooCommerce Alpha and Release-Alpha Build Configuration.

I then ran the app. Stopped Xcode debug when it crashed. And then I opened the app multiple times in the simulator to make it crash a few more times.

I was hoping that the events will turn up in Sentry. I waited for 5 minutes but they never did.

So, I removed the code above so the app will not crash anymore. And that's when the crashes turned up in Sentry. This hints that Sentry never got a chance to submit the events to the API because the app crashed right away. I believe this is what will happen in production too. We will still not receive the crashes in Sentry because the app keeps crashing immediately after opening.

This is all just coming back to me, my apologies. I now remember that we implemented a thread-blocking submission of events in WPiOS so that the Sentry client will have a chance to upload the events to the API.

We can implement the same thing here. Possibly just replacing the logMessage calls with the logErrorAndWait() from WP.

This is not ideal. I still believe that we should not crash and show a message to the user instead. But in the meantime, we can go with the forced logging.

@jaclync jaclync changed the base branch from fix/setup-crash-logging-as-first-thing to release/4.4 June 2, 2020 00:00
Copy link
Contributor Author

@jaclync jaclync left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used WooCommerce Alpha and Release-Alpha Build Configuration.
I then ran the app. Stopped Xcode debug when it crashed. And then I opened the app multiple times in the simulator to make it crash a few more times.
I was hoping that the events will turn up in Sentry. I waited for 5 minutes but they never did.
So, I removed the code above so the app will not crash anymore. And that's when the crashes turned up in Sentry. This hints that Sentry never got a chance to submit the events to the API because the app crashed right away. I believe this is what will happen in production too. We will still not receive the crashes in Sentry because the app keeps crashing immediately after opening.
This is all just coming back to me, my apologies. I now remember that we implemented a thread-blocking submission of events in WPiOS so that the Sentry client will have a chance to upload the events to the API.

this is a really good point, I didn't think of this case and test with a fatalError after the logging call. I updated the logging that is followed by a fatalError to be logErrorAndWait like in WPiOS in 121ba3f

Additionally, I added the application state to the logging in b16bab2 since this could help us understand more about the permission issues based on Jeremy's feedback in p91TBi-2R9-p2

Ready for another pass and lemme know if you still don't see the events on Sentry!

Copy link
Member

@shiki shiki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Thank you for working on this, @jaclync! :shipit:

I retested the flow I mentioned yesterday and it now works!

@jaclync
Copy link
Contributor Author

jaclync commented Jun 3, 2020

@loremattei merging this PR to release 4.4 now for the next beta build, thanks for wrangling the release!

@jaclync jaclync merged commit 537bb9b into release/4.4 Jun 3, 2020
@jaclync jaclync deleted the issue/2364-log-crashes-in-storage branch June 3, 2020 09:18
@loremattei
Copy link
Contributor

@jaclync perfect! Thank you!
I'm going to release a new beta tomorrow!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: crash The worst kind of bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants