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

Add Sentry User Data #12155

Merged
merged 11 commits into from
Jun 15, 2020
Merged

Add Sentry User Data #12155

merged 11 commits into from
Jun 15, 2020

Conversation

jkmassel
Copy link
Contributor

@jkmassel jkmassel commented Jun 10, 2020

Adds WordPress.com account userID, username, and email address to crash logs.

To test:

  1. Smoke test – launch the app + log in to ensure that Sentry is initialized correctly and the DI stuff is working.
  2. Add require(false) to a Kotlin file where you can trigger it (I'd suggest PagesActivity.kt)
  3. Add return true to the top of CrashLogging.shouldSendEvents to ensure events are sent to Sentry regardless of environment.
  4. Run (not debug) this branch on-device, then trigger the crash and relaunch the app.
  5. Verify that the crash shows up in Sentry with your user details associated.

Next Steps:

  • I'd like to get the app using the Tracks version of Sentry in order to make things consistent with the other apps, but that should be a separate PR.
  • If a user logs in and experiences a crash in the same session, their user data will not be sent with the crash. The Tracks version of the Sentry integration has a mechanism for handling this transition, so I'd like to do that work once.

PR submission checklist:

  • I have considered adding unit tests where possible.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented Jun 10, 2020

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

@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented Jun 10, 2020

You can test the changes on this Pull Request by downloading the APK here.

@jkmassel jkmassel force-pushed the add/sentry-user-data branch 5 times, most recently from f5873f5 to 2b57574 Compare June 11, 2020 00:38
@jkmassel jkmassel requested a review from oguzkocer June 11, 2020 04:13
@jkmassel jkmassel self-assigned this Jun 11, 2020
@jkmassel jkmassel added this to the 15.1 milestone Jun 11, 2020
@jkmassel jkmassel force-pushed the add/sentry-user-data branch from 2b57574 to e08a479 Compare June 11, 2020 04:15
"User shouldn't be able to open a trashed post in an editor " +
"without publishing rights."
)
AppLog.e(T.EDITOR, "User shouldn't be able to open a trashed post in an editor " +
Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMHO if we're concerned about this, we should either crash if we're in an invalid state, OR we could just do the right thing, but for now we have the log.


Sentry.setTag("version", BuildConfig.VERSION_NAME)

this.accountStore.account.apply {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't deal with user account transitions. I thought about moving it to beforeSend, but the issue there is that it's called when Sentry starts up, and I'm not sure if the accountStore has the user data at that point, so it sort of becomes a hidden dependency.

As noted in the PR description, the Tracks version of this code is a bit more resilient against this sort of issue, so the next step will be tackling that migration.

Copy link
Contributor

Choose a reason for hiding this comment

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

Account transitions can be handled in a different way, but I am not sure if I understand why using beforeSend would be an issue. Since beforeSend is a callback, it should be called just before sending the error. Also, since AccountStore is a argument passed in the constructor it should be ready to use at any point in this class. Am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Chatted about this separately – because FluxC still reads from the DB on initialization, this should always be correct internally.

Changed in 7941de4

@jkmassel jkmassel marked this pull request as ready for review June 11, 2020 04:28
@oguzkocer oguzkocer assigned oguzkocer and unassigned jkmassel Jun 11, 2020
Copy link
Contributor

@oguzkocer oguzkocer left a comment

Choose a reason for hiding this comment

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

@jkmassel Looks good. I left some minor suggestions/questions. Let me know what you think about them.

I've also tested the changes and verified the user info showed up in https://sentry.io/share/issue/27e9f284baff4569a93b0161f6459a5f/.

* @param[tag] An optional [AppLog] tag
*/
@JvmOverloads
fun logException(tr: Throwable, tag: AppLog.T? = null) = this.log(tr.toString(), tag)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use throwable instead of tr for the parameter name? Named arguments are pretty common in Kotlin and I don't think tr immediately means throwable. This applies to reportException method as well.

Copy link
Contributor Author

@jkmassel jkmassel Jun 11, 2020

Choose a reason for hiding this comment

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

For sure – fixed in c54bc21

Comment on lines +104 to +105
Sentry.removeExtra("tag")
Sentry.removeTag("tag")
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume we remove these so it doesn't affect future events. I think this might not be super clear to everyone else, so should we add a comment on top of them to explain this? If we do that, can we do it for reportException as well?

Copy link
Contributor Author

@jkmassel jkmassel Jun 11, 2020

Choose a reason for hiding this comment

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

Also fixed in c54bc21

@jkmassel jkmassel force-pushed the add/sentry-user-data branch from a34c5b7 to c54bc21 Compare June 11, 2020 22:22
@jkmassel jkmassel requested a review from oguzkocer June 11, 2020 22:43
@jkmassel jkmassel force-pushed the add/sentry-user-data branch from 5ef3875 to 946bb9f Compare June 12, 2020 21:52
@jkmassel jkmassel force-pushed the add/sentry-user-data branch from 946bb9f to 5fc737d Compare June 12, 2020 21:53
# Conflicts:
#	WordPress/src/main/java/org/wordpress/android/modules/AppComponent.java
@oguzkocer oguzkocer merged commit d8b4ef7 into develop Jun 15, 2020
@oguzkocer oguzkocer deleted the add/sentry-user-data branch June 15, 2020 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants