Skip to content

Adds Sentry Performance Monitoring Capabilities#18496

Merged
oguzkocer merged 4 commits intotrunkfrom
enable/sentry-performance-monitoring
May 24, 2023
Merged

Adds Sentry Performance Monitoring Capabilities#18496
oguzkocer merged 4 commits intotrunkfrom
enable/sentry-performance-monitoring

Conversation

@oguzkocer
Copy link
Copy Markdown
Contributor

@oguzkocer oguzkocer commented May 23, 2023

This PR adds Sentry Performance Monitoring capabilities that's managed through a Firebase remote config. It's disabled for debug builds as well as for users who has tracking disabled. It's also disabled by default and will only work if we set the wp_android_performance_monitoring_sample_rate remote config value in the range of 0 < sampleRate <=1.0. The implementation closely follows it's counterpart from WooCommerce-Android project.

The remote config value is set to 0.0 for now. I intend to keep it this way and let folks who are interested in this capability to change the sampling rate as they see fit. This is to prevent us from accidentally sending too many events and getting a large bill to pay.

Note that the TransactionLaunchers and transactions for HTTP requests are out of scope for this PR. We'll need to have an internal discussion about that before we add them.

To test:

Admittedly I don't know how we should test this implementation. The implementation is unit tested and following the implementation from WCAndroid, so I am hopeful that it will work. However, if there is a good way to test this, I'd like to do that before we merge the PR.

@wzieba I'd love to hear your thoughts on testing since you worked on this for WCAndroid. Thanks in advance!

Regression Notes

  1. Potential unintended areas of impact
    N/A

  2. What I did to test those areas of impact (or what existing automated tests I relied on)
    N/A

  3. What automated tests I added (or what prevented me from doing so)
    N/A

PR submission checklist:

  • I have completed the Regression Notes.
  • 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.

UI Changes testing checklist:

  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • Talkback.
  • Languages with large words or with letters/accents not frequently used in English.
  • Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)
  • Large and small screen sizes. (Tablet and smaller phones)
  • Multi-tasking: Split screen and Pop-up view. (Android 10 or higher)

@oguzkocer oguzkocer added this to the 22.5 milestone May 23, 2023
@wpmobilebot
Copy link
Copy Markdown
Contributor

WordPress📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress WordPress
FlavorJalapeno
Build TypeDebug
Versionpr18496-704e77f
Commit704e77f
Direct Downloadwordpress-prototype-build-pr18496-704e77f.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Copy Markdown
Contributor

Jetpack📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack Jetpack
FlavorJalapeno
Build TypeDebug
Versionpr18496-704e77f
Commit704e77f
Direct Downloadjetpack-prototype-build-pr18496-704e77f.apk
Note: Google Login is not supported on these builds.

@oguzkocer oguzkocer marked this pull request as ready for review May 23, 2023 13:16
@oguzkocer oguzkocer enabled auto-merge May 23, 2023 13:19
@oguzkocer oguzkocer requested review from ParaskP7 and wzieba May 23, 2023 13:19
@ParaskP7 ParaskP7 self-assigned this May 24, 2023
Copy link
Copy Markdown
Contributor

@ParaskP7 ParaskP7 left a comment

Choose a reason for hiding this comment

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

👋 @oguzkocer !

I have reviewed this PR as per the instructions, everything LGTM and in par with WCAndroid. Good job bringing Sentry's performance monitoring to WPAndroid and making it configurable via Firebase remote config! 🌟 💯 🥇


Admittedly I don't know how we should test this implementation. The implementation is unit tested and following the implementation from WCAndroid, so I am hopeful that it will work. However, if there is a good way to test this, I'd like to do that before we merge the PR.

Same! 😊

PS: All I did is verifying that the Firebase related wp_android_performance_monitoring_sample_rate remote config has been indeed created and has the expected parameter values.

@wzieba I'd love to hear your thoughts on testing since you worked on this for WCAndroid. Thanks in advance!

This! ⬆️

PS: I am going to approve this PR, just to unblock it, but getting @wzieba input before merging is very welcome.

private const val VALID_SAMPLE_RATE = 0.01
private const val INVALID_SAMPLE_RATE = 0.0

class WPPerformanceMonitoringConfigTest {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Praise (❤️): Awesome work on the tests, many thanks for covering as many scenarios as possible! 🥇

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I borrowed 3/4 of these tests from @wzieba's implementation ❤️

companion object {
private const val PERFORMANCE_MONITORING_SAMPLE_RATE_KEY = "wp_android_performance_monitoring_sample_rate"

const val OPEN_WEB_LINKS_WITH_JETPACK_FLOW_FREQUENCY_KEY = "open_web_links_with_jetpack_flow_frequency"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor (🔍): Not related to your change, but maybe we should consider making this constant private as well. Feel free to totally ignore this comment. 😊

@oguzkocer oguzkocer merged commit babc8a9 into trunk May 24, 2023
@oguzkocer oguzkocer deleted the enable/sentry-performance-monitoring branch May 24, 2023 10:00
@ParaskP7
Copy link
Copy Markdown
Contributor

😞 Ah, this just got merged due to auto-merged being enabled. I usually don't check for auto-merge being enabled on such PRs, especially when extra feedback is waited upon, apologies @oguzkocer , I should have checked anyway! 😭

@wzieba
Copy link
Copy Markdown
Contributor

wzieba commented May 24, 2023

👋 I don't see anything blocking in this PR so I think the merge was safe!

What I could suggest is:

  1. Integrate CrashLoggingOkHttpInterceptor to have HTTP spans added in performance transaction. I believe that for our mobile apps, it's the most crucial part.

  2. You can enable adding database operations spans by updating Sentry Gradle Plugin settings:

sentry {
    tracingInstrumentation {
        enabled = true
        features = [io.sentry.android.gradle.extensions.InstrumentationFeature.DATABASE]
    }
}

About testing: Sentry adds default transactions for all activities and start of the app. I'm installing the app now to check if the integration works.

@wzieba
Copy link
Copy Markdown
Contributor

wzieba commented May 24, 2023

It's alive!

image

@wzieba
Copy link
Copy Markdown
Contributor

wzieba commented May 24, 2023

I also see that the network interceptor was added automatically by Sentry.

It's good but not perfect - adding our own network interceptor allows us to specify our own com.automattic.android.tracks.crashlogging.RequestFormatter. We should use RequestFormatter to remove data like blog_id or post_id from requests to:

  • increase privacy
  • make it possible for Sentry to merge the same types of network spans when it analyzes performance transactions.

A sample RequestFormatter can be found here - see unit tests to see how it works. I think it can be safely reused in WordPress / Jetpack apps.


I see that Sentry also enables, by default, database operations spans, but I think they're safe to leave as it is.

@oguzkocer
Copy link
Copy Markdown
Contributor Author

@ParaskP7 @wzieba Thank you both for the review! I shouldn't have enabled auto-merge for this PR, sorry about that!

I'm working on a follow up PR to apply the suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants