firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.28k stars 578 forks source link

Crashlytics custom key not being set as expected #6341

Closed spectrl closed 1 month ago

spectrl commented 1 month ago

[READ] Step 1: Are you in the right place?

Issues filed here should be about bugs in the code in this repository. If you have a general question, need help debugging, or fall into some other category use one of these other channels:

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

I'm trying to set a custom key temporarily per recorded log/exception and I'd expect the tag I have set prior to calling log or recordException to be present in the dashboard as I "send" (I know they get queued) the event immediately after setting the tag, but before unsetting it. However the custom key that does actually get set is the empty string one "" (see screenshot).

The docs suggest this should not be the case:

Sets a custom key and value that are associated with subsequent fatal, non-fatal, and ANR reports. Multiple calls to this method with the same key update the value for that key. The value of any key at the time of a fatal, non-fatal, or ANR event is associated with that event.

Is there a way to get this to work or is it inherently asynchronous somewhere?

Steps to reproduce:

Run the code below.

Relevant Code:

val crashlytics = Firebase.crashlytics
val tagKey = "tag"
try {
    val logTag = "Some temporary tag"
    crashlytics.setCustomKey(tagKey, logTag)
    crashlytics.log(message)
    crashlytics.recordException(throwable)
} finally {
    crashlytics.setCustomKey(tagKey, "")
}
lehcar09 commented 1 month ago

Hi @spectrl, thank you for reaching out and reporting the issue. I was able to reproduce the issue in the Firebase SDK version BOM 33.3.0 you're using.

However, the issue is fixed in the latest Firebase SDK version BOM 33.4.0. Upon checking, with the code snippet you shared, the value Some temporary tag of custom key tag was retained even after setting the value to blank. Please update to the latest SDK version to get the latest improvements and fix that might be causing the issue.

That said, I’ll be closing the issue now. Let me know if there’s any misunderstanding or we need to reopen the issue for further investigation. Thanks!