setCustomKey doesn't work in firebase crashlytics

Viewed 79

Following the docs, I've added:

FirebaseCrashlytics.getInstance().setCustomKey("my_string_key", "foo" /* string value */)

I'm using the latest version of crashlytics:

implementation platform('com.google.firebase:firebase-bom:30.3.1')
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-analytics'

I've forced a crash like this:

throw RuntimeException("Test Crash6")

The crash is showing up in the dashboard, but not the custom key:

enter image description here

enter image description here

1 Answers

in onCreate method in every activity and after:

 super.onCreate(savedInstanceState);

write this code:

           Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        Thread.UncaughtExceptionHandler defaultHandler;

        {
            defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
        }

        @Override
        public void uncaughtException(@NonNull Thread thread, @NonNull Throwable throwable) {
            String AymanError = throwable +
                    "\n====>>>  Error in: " + Arrays.toString(Objects.requireNonNull(throwable.getCause()).getStackTrace());

            FirebaseCrashlytics.getInstance().log(AymanError);

            FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();

            crashlytics.setCustomKey("ayman_string_key", AymanError /* string value */);


            defaultHandler.uncaughtException(thread, throwable);


        }
    });

This works for me perfectly . it appears in crash details as here: enter image description here

and in main Crashlytics menu by writing the key name :

key:key_name

Like here: enter image description here

Related