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 spannable tracking around SyncResponseHandler #7514

Merged
merged 8 commits into from
Nov 10, 2022

Conversation

amitkma
Copy link
Contributor

@amitkma amitkma commented Nov 2, 2022

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

  • A new plugin SyncDurationMetricPlugin is added.
  • Sentry tracking can now track spans within transactions.

Motivation and context

  • In order to improve the crypto layer, we need to have some metrics to track and improve. sync_response_handler is one of such metrics.

Tests

  • Enable analytics in Element-Android app.
  • Try to open some conversations (rooms), especially the ones for which you don't have keys yet.
  • You must see the count of download_device_keys increasing here.

Tested devices

  • Physical
  • Emulator
  • OS version(s): Android 11 and 12

Checklist

@amitkma amitkma self-assigned this Nov 3, 2022
@amitkma amitkma marked this pull request as ready for review November 4, 2022 10:47
@amitkma amitkma requested review from a team and mnaturel and removed request for a team November 4, 2022 10:47
@@ -17,12 +17,16 @@
package org.matrix.android.sdk.api.extensions
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why this class is called MetricsExtensions and is in the package extensions? It seems to me there is no extension methods in this file. Maybe we should rename and move it somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, you are right. Initially, I was thinking of making them as extension of MetricsPlugin but now they are just functions so we need to rename it.

Timber.v("Should start cryptoService")
cryptoService.start()
val relevantPlugins = metricPlugins.filterIsInstance<SyncDurationMetricPlugin>()
measureMetric(relevantPlugins) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should try to improve readability of this code, what about extracting all the steps in dedicated small methods. And we could also avoid adding comments using good naming for these methods. For example:

measureMetric(relevantPlugins) {
    startCryptoService()
    handleToDevice()
    ...
}

Copy link
Contributor

@mnaturel mnaturel left a comment

Choose a reason for hiding this comment

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

LGTM, I have added some suggestions to improve readability of the sync response handling.

Please can you also add a changelog entry?

}

private fun markCryptoSyncCompleted(syncResponse: SyncResponse) {
// "crypto_sync_handler_onSyncCompleted" span
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it is useful to keep these comments about spans since now we have dedicated private methods?

* @param block Action/Task to be executed within this span.
*/
@OptIn(ExperimentalContracts::class)
inline fun List<MetricPlugin>.measureMetric(block: () -> Unit) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I think we should update to avoid any confusion.

@mnaturel
Copy link
Contributor

mnaturel commented Nov 9, 2022

@amitkma When testing the last build I am blocked at a certain step during initial sync (see capture below). Do you reproduce this issue as well? Maybe something related to the refactoring?

@amitkma
Copy link
Contributor Author

amitkma commented Nov 9, 2022

@amitkma When testing the last build I am blocked at a certain step during initial sync (see capture below). Do you reproduce this issue as well? Maybe something related to the refactoring?

Yes I do see it and I am looking into it. One of our test is also failing due to this issue.

Copy link
Contributor

@mnaturel mnaturel left a comment

Choose a reason for hiding this comment

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

Thanks for the updates. LGTM not blocked during initial sync after testing the latest build.

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

63.7% 63.7% Coverage
0.0% 0.0% Duplication

@amitkma amitkma merged commit c07b110 into develop Nov 10, 2022
@amitkma amitkma deleted the feature/amitkma/sync-duration-tracking branch November 10, 2022 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants