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

Report sync failures to Crashlytics #2752

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class FirebaseCrashLogger @Inject constructor() {
}
}

fun logException(t: Throwable) {
if (isReleaseBuild()) {
FirebaseCrashlytics.getInstance().recordException(t)
}
}

fun setSelectedSurveyId(surveyId: String?) {
setCustomKeys { key("selectedSurveyId", surveyId ?: "") }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.work.Data
import androidx.work.ListenableWorker.Result.retry
import androidx.work.ListenableWorker.Result.success
import androidx.work.WorkerParameters
import com.google.android.ground.FirebaseCrashLogger
import com.google.android.ground.model.User
import com.google.android.ground.model.mutation.Mutation
import com.google.android.ground.persistence.local.room.fields.MutationEntitySyncStatus
Expand Down Expand Up @@ -122,6 +123,9 @@ constructor(
// Mark all mutations as having failed since the remote datastore only commits when all
// mutations have succeeded.
Timber.d(t, "Local mutation sync failed")
val crashlytics = FirebaseCrashLogger()
crashlytics.setSelectedSurveyId(mutations.first().surveyId)
crashlytics.logException(t)
mutationRepository.markAsFailed(mutations, t)
false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import androidx.work.Data
import androidx.work.WorkerParameters
import com.google.android.ground.Config
import com.google.android.ground.FirebaseCrashLogger
import com.google.android.ground.model.mutation.Mutation
import com.google.android.ground.model.mutation.SubmissionMutation
import com.google.android.ground.model.submission.isNotNullOrEmpty
Expand Down Expand Up @@ -141,9 +142,10 @@
return try {
remoteStorageManager.uploadMediaFromFile(photoFile, path)
kotlin.Result.success(Unit)
} catch (e: Exception) {
Timber.e("Photo upload failed. local path: ${photoFile.path}, remote path: $path", e)
kotlin.Result.failure(e)
} catch (t: Throwable) {
Timber.e("Photo upload failed. local path: ${photoFile.path}, remote path: $path", t)
FirebaseCrashLogger().logException(t)

Check warning on line 147 in ground/src/main/java/com/google/android/ground/persistence/sync/MediaUploadWorker.kt

View check run for this annotation

Codecov / codecov/patch

ground/src/main/java/com/google/android/ground/persistence/sync/MediaUploadWorker.kt#L145-L147

Added lines #L145 - L147 were not covered by tests
kotlin.Result.failure(t)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import androidx.work.Data
import androidx.work.WorkerParameters
import com.google.android.ground.Config.MAX_SYNC_WORKER_RETRY_ATTEMPTS
import com.google.android.ground.FirebaseCrashLogger
import com.google.android.ground.domain.usecases.survey.SyncSurveyUseCase
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
Expand Down Expand Up @@ -51,12 +52,15 @@
try {
Timber.d("Syncing survey $surveyId")
syncSurvey(surveyId)
} catch (e: Throwable) {
} catch (t: Throwable) {
val logger = FirebaseCrashLogger()
logger.setSelectedSurveyId(surveyId)
logger.logException(t)
return if (this.runAttemptCount > MAX_SYNC_WORKER_RETRY_ATTEMPTS) {
Timber.v(e, "Survey sync failed too many times. Giving up.")
Timber.v(t, "Survey sync failed too many times. Giving up.")

Check warning on line 60 in ground/src/main/java/com/google/android/ground/persistence/sync/SurveySyncWorker.kt

View check run for this annotation

Codecov / codecov/patch

ground/src/main/java/com/google/android/ground/persistence/sync/SurveySyncWorker.kt#L60

Added line #L60 was not covered by tests
Result.failure()
} else {
Timber.v(e, "Survey sync. Retrying...")
Timber.v(t, "Survey sync. Retrying...")
Result.retry()
}
}
Expand Down