Sentry: Report sync duration and metrics for initial sync and for sync after pause. Not for regular sync.

This commit is contained in:
Benoit Marty 2023-01-20 14:01:35 +01:00
parent 2e8ed1bef2
commit 1a08a9425b
4 changed files with 12 additions and 4 deletions

View File

@ -29,4 +29,6 @@ interface SyncDurationMetricPlugin : SpannableMetricPlugin {
override fun logTransaction(message: String?) {
Timber.tag(loggerTag.value).v("## syncResponseHandler() : $message")
}
fun shouldReport(isInitialSync: Boolean, isAfterPause: Boolean): Boolean = true
}

View File

@ -68,12 +68,13 @@ internal class SyncResponseHandler @Inject constructor(
suspend fun handleResponse(
syncResponse: SyncResponse,
fromToken: String?,
afterPause: Boolean,
reporter: ProgressReporter?
) {
val isInitialSync = fromToken == null
Timber.v("Start handling sync, is InitialSync: $isInitialSync")
relevantPlugins.measureSpannableMetric {
relevantPlugins.filter { it.shouldReport(isInitialSync, afterPause) }.measureSpannableMetric {
startCryptoService(isInitialSync)
// Handle the to device events before the room ones

View File

@ -151,7 +151,7 @@ internal class DefaultSyncTask @Inject constructor(
syncStatisticsData.requestInitSyncTime = SystemClock.elapsedRealtime()
syncStatisticsData.downloadInitSyncTime = syncStatisticsData.requestInitSyncTime
logDuration("INIT_SYNC Database insertion", loggerTag, clock) {
syncResponseHandler.handleResponse(syncResponse, token, syncRequestStateTracker)
syncResponseHandler.handleResponse(syncResponse, null, afterPause = true, syncRequestStateTracker)
}
syncResponseToReturn = syncResponse
}
@ -184,7 +184,7 @@ internal class DefaultSyncTask @Inject constructor(
toDevice = nbToDevice,
)
)
syncResponseHandler.handleResponse(syncResponse, token, null)
syncResponseHandler.handleResponse(syncResponse, token, afterPause = params.afterPause, null)
syncResponseToReturn = syncResponse
Timber.tag(loggerTag.value).d("Incremental sync done")
syncRequestStateTracker.setSyncRequestState(SyncRequestState.IncrementalSyncDone)
@ -264,7 +264,7 @@ internal class DefaultSyncTask @Inject constructor(
Timber.tag(loggerTag.value).d("INIT_SYNC $nbOfJoinedRooms rooms, $nbOfJoinedRoomsInFile ephemeral stored into files")
logDuration("INIT_SYNC Database insertion", loggerTag, clock) {
syncResponseHandler.handleResponse(syncResponse, null, syncRequestStateTracker)
syncResponseHandler.handleResponse(syncResponse, null, afterPause = true, syncRequestStateTracker)
}
initialSyncStatusRepository.setStep(InitialSyncStatus.STEP_SUCCESS)
syncResponse

View File

@ -34,6 +34,11 @@ class SentrySyncDurationMetrics @Inject constructor() : SyncDurationMetricPlugin
// Stacks to keep spans in LIFO order.
private var spans: Stack<ISpan> = Stack()
override fun shouldReport(isInitialSync: Boolean, isAfterPause: Boolean): Boolean {
// Report only for initial sync and for sync after pause
return isInitialSync || isAfterPause
}
/**
* Starts the span for a sub-task.
*