-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apollo: Release source code for 49.4
- Loading branch information
Showing
37 changed files
with
347 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
android/apollo/src/main/java/io/muun/apollo/data/logging/Crashlytics.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package io.muun.apollo.data.logging | ||
|
||
import com.google.firebase.crashlytics.FirebaseCrashlytics | ||
import io.muun.apollo.domain.action.debug.ForceCrashReportAction | ||
import io.muun.apollo.domain.errors.CyclicalSwapError | ||
import io.muun.apollo.domain.errors.FcmTokenNotAvailableError | ||
import io.muun.apollo.domain.errors.InvoiceAlreadyUsedException | ||
import io.muun.apollo.domain.errors.InvoiceExpiredException | ||
import io.muun.apollo.domain.errors.InvoiceExpiresTooSoonException | ||
import io.muun.apollo.domain.errors.InvoiceMissingAmountException | ||
import io.muun.apollo.domain.errors.NoPaymentRouteException | ||
import io.muun.apollo.domain.errors.UnreachableNodeException | ||
import io.muun.apollo.domain.model.report.CrashReport | ||
import io.muun.apollo.domain.utils.isInstanceOrIsCausedByError | ||
|
||
object Crashlytics { | ||
|
||
private val crashlytics = FirebaseCrashlytics.getInstance() | ||
|
||
/** | ||
* Set up Crashlytics metadata. | ||
*/ | ||
@JvmStatic | ||
fun configure(email: String?, userId: String) { | ||
crashlytics.setUserId(userId) | ||
crashlytics.setCustomKey("email", email ?: "unknown") | ||
|
||
// TODO: use setUserEmail, and grab Houston session UUID to attach it | ||
} | ||
|
||
/** | ||
* Add custom log event, to be displayed under Logs tab. Also queryable via Bigquery. See: | ||
* https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=android#add-logs | ||
*/ | ||
@JvmStatic | ||
fun logBreadcrumb(breadcrumb: String) { | ||
crashlytics.log(breadcrumb); | ||
} | ||
|
||
/** | ||
* Send the error to Crashlytics, attaching metadata as key-values with their SDK. | ||
*/ | ||
fun reportError(report: CrashReport) { | ||
|
||
// Silence some common "nothing to worry about" errors | ||
if (isOnCrashlyticsBlacklist(report.originalError)) { | ||
return | ||
} | ||
|
||
crashlytics.setCustomKey("tag", report.tag) | ||
crashlytics.setCustomKey("message", report.message) | ||
crashlytics.setCustomKey("locale", LoggingContext.locale) | ||
|
||
for (entry in report.metadata.entries) { | ||
crashlytics.setCustomKey(entry.key, entry.value.toString()) | ||
} | ||
|
||
crashlytics.recordException(report.error) | ||
} | ||
|
||
/** | ||
* Send a "fallback" reporting error to Crashlytics. This means that there was an error while | ||
* doing our usual error report processing. Hence we try to report the original error data (tag, | ||
* message, error) and the error that happened while reporting. | ||
*/ | ||
fun reportReportingError( | ||
tag: String?, | ||
message: String?, | ||
originalError: Throwable?, | ||
crashReportingError: Throwable, | ||
) { | ||
|
||
tag?.let { crashlytics.setCustomKey("tag", it) } | ||
message?.let { crashlytics.setCustomKey("message", it) } | ||
|
||
if (originalError != null) { | ||
crashlytics.recordException(originalError) | ||
} | ||
|
||
crashlytics.recordException(crashReportingError) | ||
} | ||
|
||
/** | ||
* Forcefully report an exception, bypassing our usual error processing. Meant to only be used | ||
* by ForceCrashReportAction. | ||
* | ||
* @see ForceCrashReportAction | ||
*/ | ||
fun forceReport(error: ForceCrashReportAction.ForcedCrashlyticsCall) { | ||
crashlytics.recordException(error) | ||
} | ||
|
||
/** | ||
* There are certain errors that are expected and/or there's nothing we can do about it (besides | ||
* properly informing the user about the situation), so let's try to reduce crashlytics noise by | ||
* silencing some common "nothing to worry about" errors. | ||
*/ | ||
private fun isOnCrashlyticsBlacklist(error: Throwable?): Boolean { | ||
|
||
// If root error has no throwable cause then there's nothing to blacklist | ||
// This is an ugly signature and behaviour to have but makes life easier for caller | ||
if (error == null) { | ||
return false | ||
} | ||
|
||
return when { | ||
error.isInstanceOrIsCausedByError<UnreachableNodeException>() -> true | ||
error.isInstanceOrIsCausedByError<NoPaymentRouteException>() -> true | ||
error.isInstanceOrIsCausedByError<InvoiceExpiredException>() -> true | ||
error.isInstanceOrIsCausedByError<InvoiceExpiresTooSoonException>() -> true | ||
error.isInstanceOrIsCausedByError<InvoiceAlreadyUsedException>() -> true | ||
error.isInstanceOrIsCausedByError<InvoiceMissingAmountException>() -> true | ||
error.isInstanceOrIsCausedByError<CyclicalSwapError>() -> true | ||
|
||
error.isInstanceOrIsCausedByError<FcmTokenNotAvailableError>() -> true | ||
|
||
else -> false | ||
} | ||
} | ||
} |
18 changes: 6 additions & 12 deletions
18
android/apollo/src/main/java/io/muun/apollo/data/logging/LoggingContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,19 @@ | ||
package io.muun.apollo.data.logging | ||
|
||
import com.google.firebase.crashlytics.FirebaseCrashlytics | ||
|
||
|
||
object LoggingContext { | ||
|
||
/** | ||
* Log errors to the Crashlytics. | ||
*/ | ||
@JvmStatic | ||
var sendToCrashlytics = true // default for production | ||
|
||
/** | ||
* Log errors to the system logs. | ||
*/ | ||
@JvmStatic | ||
var sendToLogcat = false // default for production | ||
|
||
@JvmStatic | ||
var locale: String = "UNSET" // easily track and attach user's locale to muun errors and reports | ||
|
||
@JvmStatic | ||
fun configure(email: String?, userId: String) { | ||
val crashlytics = FirebaseCrashlytics.getInstance() | ||
crashlytics.setUserId(userId) | ||
crashlytics.setCustomKey("email", email ?: "unknown") | ||
|
||
// TODO: use setUserEmail, and grab Houston session UUID to attach it | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.