feat: upload diagnostics with redaction and crash capture
- 500-entry local ring buffer, immediate flush for warnings/errors - batch upload to POST /logs with device id, platform, version and session - redact tokens, Authorization headers and secrets before storage/upload - Android/desktop uncaught handlers persist a crash entry for the next launch - Settings diagnostics card with pending count, send now and clear - fall back cleanly when the server predates /logs - include X-Request-Id in API failure diagnostics; version 0.4.3
This commit is contained in:
1 parent
4d5a97cdac
commit
b1ccfc9ee1
20 files changed
+820
-21
No files matched your search
+26
@@ -0,0 +1,26 @@
|
||||
package win.taptap.musicmanager.client
|
||||
|
||||
import android.app.Application
|
||||
import win.taptap.musicmanager.client.logging.AppLog
|
||||
|
||||
/**
|
||||
* Initializes diagnostics before the activity exists and records the one case
|
||||
* the in-app logger cannot: an uncaught exception. The line is persisted
|
||||
* synchronously and uploaded on the next launch.
|
||||
*/
|
||||
class AudioManagerApplication : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
AndroidContextHolder.context = applicationContext
|
||||
AppLog.init(platformStorage())
|
||||
|
||||
val previous = Thread.getDefaultUncaughtExceptionHandler()
|
||||
Thread.setDefaultUncaughtExceptionHandler { thread, error ->
|
||||
runCatching {
|
||||
AppLog.error("crash", "Uncaught exception on ${thread.name}", error)
|
||||
AppLog.flushNow()
|
||||
}
|
||||
previous?.uncaughtException(thread, error)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,3 +135,7 @@ class AndroidStorage(context: Context) : AppStorage {
|
||||
|
||||
actual fun decodeImage(bytes: ByteArray): ImageBitmap? =
|
||||
BitmapFactory.decodeByteArray(bytes, 0, bytes.size)?.asImageBitmap()
|
||||
|
||||
private val LOG_LOCK = Any()
|
||||
|
||||
internal actual fun <T> withLogLock(block: () -> T): T = synchronized(LOG_LOCK) { block() }
|
||||
Reference in new issue
Block a user