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

Add a kotlin method for recording an exception with custom keys #6546

Merged
merged 49 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
71fff26
Initial implementation of recording a custom key value pair in record…
tejasd Nov 20, 2024
981a51e
Fix unit tests affected by EventMetadata
tejasd Nov 21, 2024
81fd3fa
Add copyright header to EventMetadata
tejasd Nov 21, 2024
2e39254
Update api.txt file
tejasd Nov 21, 2024
f6196e2
Add a JvmOverload in EventMetadata to use the default value for userInfo
tejasd Nov 21, 2024
38a4a26
Add a unit test to verify the behavior of userInfo keys
tejasd Nov 21, 2024
7c422bb
Update documentation of EventMetadata
tejasd Nov 21, 2024
9f99b44
Remove TODO
tejasd Nov 21, 2024
bb3aae2
Additional documentation for EventMetadata
tejasd Nov 21, 2024
c02234e
Add details to CHANGELOG
tejasd Nov 21, 2024
1b5f09e
Merge branch 'main' into td/record-exception
tejasd Nov 21, 2024
590cc9a
Merge branch 'main' into td/record-exception
tejasd Nov 25, 2024
5fdeade
Refactor the merging of event and global keys into a method, and add …
tejasd Nov 25, 2024
dfaf14d
Add a TODO
tejasd Nov 25, 2024
8a3b6e9
Revert CHANGELOG
tejasd Nov 26, 2024
f30f48c
Merge branch 'main' into td/record-exception
tejasd Nov 26, 2024
19fce3e
Fix typo
tejasd Nov 26, 2024
92e133a
Fix CHANGELOG
tejasd Nov 26, 2024
4d58ecd
unused import
tejasd Nov 26, 2024
f465408
Refactor the method to merge event and global keys
tejasd Nov 26, 2024
d0d7c53
return unmodifiable map
tejasd Nov 26, 2024
4e4f1bf
Fix accidental new lines
tejasd Nov 26, 2024
b0a3bfc
Add missing continue
tejasd Nov 26, 2024
abd31d3
Update unit tests
tejasd Nov 26, 2024
16648c0
Explicitly differentiate between internal and external keys in the Se…
tejasd Nov 26, 2024
2c4942f
Change back behavior in empty event keys, and add additional unit tests
tejasd Nov 26, 2024
9cd5814
Add extra tests and fix a bug in adding event keys
tejasd Nov 27, 2024
ca6f434
additional unit test changes
tejasd Nov 27, 2024
12142f5
additional unit test changes
tejasd Nov 27, 2024
d13605e
Rename userInfo in EventMetadata to additionalCustomKeys
tejasd Nov 27, 2024
c3cf46b
Update javadoc
tejasd Nov 27, 2024
4471d23
Update comment
tejasd Nov 27, 2024
bbfc5e8
more javadoc updates
tejasd Nov 27, 2024
dcc33e6
Rename userInfo to eventKeys where applicable
tejasd Nov 27, 2024
af2ddb1
update doc
tejasd Nov 27, 2024
85179cc
Merge branch 'main' into td/record-exception
tejasd Nov 27, 2024
c88649e
Remove LinkedHashMap TODO.
tejasd Nov 27, 2024
b384a7c
Update the public API
tejasd Nov 27, 2024
658f870
Restore null throwable loggingin the original recordException
tejasd Nov 27, 2024
6144c29
Update api.txt
tejasd Nov 27, 2024
bf9d546
Merge branch 'main' into td/record-exception
tejasd Nov 28, 2024
dda33f3
Merge branch 'main' into td/record-exception
tejasd Nov 29, 2024
a26058d
Add a kotlin method for recording an exception with custom keys
tejasd Nov 29, 2024
7554664
Update method doc
tejasd Nov 29, 2024
62eace8
Update method doc
tejasd Nov 29, 2024
9303774
Update method doc
tejasd Nov 29, 2024
be1ce95
Update comment
tejasd Nov 29, 2024
d0d9c82
Merge branch 'main' into td/record-exception-ktx
tejasd Dec 5, 2024
ae29ffc
Update api.txt
tejasd Dec 5, 2024
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
3 changes: 2 additions & 1 deletion firebase-crashlytics/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ package com.google.firebase.crashlytics {

public final class FirebaseCrashlyticsKt {
method @NonNull public static com.google.firebase.crashlytics.FirebaseCrashlytics getCrashlytics(@NonNull com.google.firebase.Firebase);
method public static void recordException(@NonNull com.google.firebase.crashlytics.FirebaseCrashlytics, @NonNull Throwable throwable, @NonNull kotlin.jvm.functions.Function1<? super com.google.firebase.crashlytics.KeyValueBuilder,kotlin.Unit> init);
method public static void setCustomKeys(@NonNull com.google.firebase.crashlytics.FirebaseCrashlytics, @NonNull kotlin.jvm.functions.Function1<? super com.google.firebase.crashlytics.KeyValueBuilder,kotlin.Unit> init);
}

public final class KeyValueBuilder {
ctor public KeyValueBuilder(@NonNull com.google.firebase.crashlytics.FirebaseCrashlytics crashlytics);
ctor @Deprecated public KeyValueBuilder(@NonNull com.google.firebase.crashlytics.FirebaseCrashlytics crashlytics);
method public void key(@NonNull String key, boolean value);
method public void key(@NonNull String key, double value);
method public void key(@NonNull String key, float value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,36 @@ class CrashlyticsTests {
@Test
fun keyValueBuilder() {
val keyValueBuilder = KeyValueBuilder()
keyValueBuilder.key("hello", "world")
keyValueBuilder.key("hello2", 23)
keyValueBuilder.key("hello3", 0.1)
keyValueBuilder.key("string", "world")
keyValueBuilder.key("int", Int.MAX_VALUE)
keyValueBuilder.key("float", Float.MAX_VALUE)
keyValueBuilder.key("boolean", true)
keyValueBuilder.key("double", Double.MAX_VALUE)
keyValueBuilder.key("long", Long.MAX_VALUE)

val result: Map<String, String> = keyValueBuilder.build().keysAndValues

assertThat(result).containsExactly("hello", "world", "hello2", "23", "hello3", "0.1")
val expectedKeys =
mapOf(
"string" to "world",
"int" to "${Int.MAX_VALUE}",
"float" to "${Float.MAX_VALUE}",
"boolean" to "${true}",
"double" to "${Double.MAX_VALUE}",
"long" to "${Long.MAX_VALUE}"
)
assertThat(result).isEqualTo(expectedKeys)
}

@Test
fun keyValueBuilder_withCrashlyticsInstance() {
@Suppress("DEPRECATION") val keyValueBuilder = KeyValueBuilder(Firebase.crashlytics)
keyValueBuilder.key("hello", "world")
keyValueBuilder.key("hello2", 23)
keyValueBuilder.key("hello3", 0.1)
keyValueBuilder.key("string", "world")
keyValueBuilder.key("int", Int.MAX_VALUE)
keyValueBuilder.key("float", Float.MAX_VALUE)
keyValueBuilder.key("boolean", true)
keyValueBuilder.key("double", Double.MAX_VALUE)
keyValueBuilder.key("long", Long.MAX_VALUE)

val result: Map<String, String> = keyValueBuilder.build().keysAndValues

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ val Firebase.crashlytics: FirebaseCrashlytics
fun FirebaseCrashlytics.setCustomKeys(init: KeyValueBuilder.() -> Unit) =
setCustomKeys(KeyValueBuilder().apply(init).build())

/** Records a non-fatal report to send to Crashlytics with additional custom keys */
fun FirebaseCrashlytics.recordException(throwable: Throwable, init: KeyValueBuilder.() -> Unit) =
recordException(throwable, KeyValueBuilder().apply(init).build())

/** @suppress */
@Keep
internal class FirebaseCrashlyticsKtxRegistrar : ComponentRegistrar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.google.firebase.crashlytics

/** Helper class to enable convenient syntax in [setCustomKeys] */
/** Helper class to enable convenient syntax in [setCustomKeys] and [recordException] */
class KeyValueBuilder
private constructor(
private val crashlytics: FirebaseCrashlytics?,
Expand Down
Loading