How to effectively group non fatal exceptions in Crashlytics (Fabrics)?

前端 未结 5 838
忘了有多久
忘了有多久 2021-01-11 19:12

We are using Crashlytics in our app as the crash reporting tool. For Android native crashes, it\'s working fine and grouping the crashes correctly. Our app also has few comp

5条回答
  •  鱼传尺愫
    2021-01-11 19:30

    I was looking into this just now, because the documentation says:

    Logged Exceptions are grouped by Exception type and message.

    Warning: Developers should avoid using unique values, such as user ID, product ID, and timestamps, in the Exception message field. Using unique values in these fields will cause a high cardinality of issues to be created. In this case, Crashlytics will limit the reporting of logged errors in your app. Unique values should instead be added to Logs and Custom Keys.

    But my experience was different. From what I found out, what Alexizamerican said in his answer is true, with a small caveat:

    Issues are grouped by the method and line where the exception was created, with the caveat that it is the root cause of the exception that is being taken into account here.

    By root cause I mean this:

    public static Throwable getRootCause(Throwable throwable) {
        Throwable cause = throwable;
        while (cause.getCause() != null) {
            cause = cause.getCause();
        }
        return cause;
    }
    

    Therefore, if you did:

    @Override
    public void handleException(Exception e) {
        // ...
        Crashlytics.logException(e);
    }
    

    That should correctly group the exceptions together.

    Furthermore, if you did:

    @Override
    public void handleException(Exception e) {
        // ...
        Crashlytics.logException(new Exception(exceptionString, e));
    }
    

    That would also correctly group the exceptions, because it would look at e or its cause, or the cause of that, and so on, until it reaches an exception that doesn't have any other cause, and look at the stack trace where it was created.

    Finally, unlike what miguel said, exception type or message doesn't affect grouping at all in my experience. If you have FooException("foo") at some particular line in a particular method, and you replace it with BarException("bar"), the two will be grouped together, because the line and method didn't change.

提交回复
热议问题