diff --git a/firebase-crashlytics/api/firebase-crashlytics.api b/firebase-crashlytics/api/firebase-crashlytics.api index 5246591bc..a70ace3c9 100644 --- a/firebase-crashlytics/api/firebase-crashlytics.api +++ b/firebase-crashlytics/api/firebase-crashlytics.api @@ -9,6 +9,7 @@ public final class dev/gitlive/firebase/crashlytics/FirebaseCrashlytics { public final fun didCrashOnPreviousExecution ()Z public final fun log (Ljava/lang/String;)V public final fun recordException (Ljava/lang/Throwable;)V + public final fun recordException (Ljava/lang/Throwable;Ljava/util/Map;)V public final fun sendUnsentReports ()V public final fun setCrashlyticsCollectionEnabled (Z)V public final fun setCustomKey (Ljava/lang/String;D)V diff --git a/firebase-crashlytics/src/androidMain/kotlin/dev/gitlive/firebase/crashlytics/crashlytics.kt b/firebase-crashlytics/src/androidMain/kotlin/dev/gitlive/firebase/crashlytics/crashlytics.kt index c749baa59..324202b98 100644 --- a/firebase-crashlytics/src/androidMain/kotlin/dev/gitlive/firebase/crashlytics/crashlytics.kt +++ b/firebase-crashlytics/src/androidMain/kotlin/dev/gitlive/firebase/crashlytics/crashlytics.kt @@ -18,6 +18,9 @@ public actual class FirebaseCrashlytics internal constructor(internal val androi public actual fun recordException(exception: Throwable) { android.recordException(exception) } + public actual fun recordException(exception: Throwable, customKeys: Map) { + android.recordException(exception, customKeys.toCustomKeysAndValues()) + } public actual fun log(message: String) { android.log(message) } @@ -53,21 +56,21 @@ public actual class FirebaseCrashlytics internal constructor(internal val androi android.setCustomKey(key, value) } public actual fun setCustomKeys(customKeys: Map) { - android.setCustomKeys( - Builder().apply { - customKeys.forEach { (key, value) -> - when (value) { - is String -> putString(key, value) - is Boolean -> putBoolean(key, value) - is Double -> putDouble(key, value) - is Float -> putFloat(key, value) - is Int -> putInt(key, value) - is Long -> putLong(key, value) - } - } - }.build(), - ) + android.setCustomKeys(customKeys.toCustomKeysAndValues()) } + + private fun Map.toCustomKeysAndValues() = Builder().apply { + forEach { (key, value) -> + when (value) { + is String -> putString(key, value) + is Boolean -> putBoolean(key, value) + is Double -> putDouble(key, value) + is Float -> putFloat(key, value) + is Int -> putInt(key, value) + is Long -> putLong(key, value) + } + } + }.build() } public actual open class FirebaseCrashlyticsException(message: String) : FirebaseException(message) diff --git a/firebase-crashlytics/src/appleMain/kotlin/dev/gitlive/firebase/crashlytics/crashlytics.kt b/firebase-crashlytics/src/appleMain/kotlin/dev/gitlive/firebase/crashlytics/crashlytics.kt index 2454d0436..9c35165d4 100644 --- a/firebase-crashlytics/src/appleMain/kotlin/dev/gitlive/firebase/crashlytics/crashlytics.kt +++ b/firebase-crashlytics/src/appleMain/kotlin/dev/gitlive/firebase/crashlytics/crashlytics.kt @@ -6,6 +6,8 @@ import platform.Foundation.NSLocalizedDescriptionKey import dev.gitlive.firebase.Firebase import dev.gitlive.firebase.FirebaseApp import dev.gitlive.firebase.FirebaseException +import kotlin.Any +import kotlin.collections.Map public val FirebaseCrashlytics.ios: FIRCrashlytics get() = FIRCrashlytics.crashlytics() @@ -19,6 +21,10 @@ public actual class FirebaseCrashlytics internal constructor(internal val ios: F public actual fun recordException(exception: Throwable) { ios.recordError(exception.asNSError()) } + @Suppress("UNCHECKED_CAST") + public actual fun recordException(exception: Throwable, customKeys: Map) { + ios.recordError(exception.asNSError(), customKeys as Map) + } public actual fun log(message: String) { ios.log(message) } diff --git a/firebase-crashlytics/src/commonMain/kotlin/dev/gitlive/firebase/crashlytics/crashlytics.kt b/firebase-crashlytics/src/commonMain/kotlin/dev/gitlive/firebase/crashlytics/crashlytics.kt index 32d99aa6c..3ebc1c4df 100644 --- a/firebase-crashlytics/src/commonMain/kotlin/dev/gitlive/firebase/crashlytics/crashlytics.kt +++ b/firebase-crashlytics/src/commonMain/kotlin/dev/gitlive/firebase/crashlytics/crashlytics.kt @@ -27,6 +27,21 @@ public expect class FirebaseCrashlytics { */ public fun recordException(exception: Throwable) + /** + * Records a non-fatal report to send to Crashlytics. + * + * Combined with app level custom keys, the event is restricted to a maximum of 64 key/value + * pairs. New keys beyond that limit are ignored. Keys or values that exceed 1024 characters are + * truncated. + * + * The values of event keys override the values of app level custom keys if they're identical. + * + * @param exception a [Throwable] to be recorded as a non-fatal event. + * @param customKeys A dictionary of keys and the values to associate with the non fatal + * exception, in addition to the app level custom keys. + */ + public fun recordException(exception: Throwable, customKeys: Map) + /** * Logs a message that's included in the next fatal, non-fatal, or ANR report. * diff --git a/firebase-crashlytics/src/jvmMain/kotlin/dev/gitlive/firebase/crashlytics/crashlytics.jvm.kt b/firebase-crashlytics/src/jvmMain/kotlin/dev/gitlive/firebase/crashlytics/crashlytics.jvm.kt index 92aba8ea9..cd5511b1b 100644 --- a/firebase-crashlytics/src/jvmMain/kotlin/dev/gitlive/firebase/crashlytics/crashlytics.jvm.kt +++ b/firebase-crashlytics/src/jvmMain/kotlin/dev/gitlive/firebase/crashlytics/crashlytics.jvm.kt @@ -17,6 +17,9 @@ actual class FirebaseCrashlytics { actual fun recordException(exception: Throwable) { } + actual fun recordException(exception: Throwable, customKeys: Map) { + } + actual fun log(message: String) { }