google analytics crash report only shows first lin

2019-03-16 07:38发布

My application uses Google Analytics to track exceptions and crashes (among other thigs). I use this function to get the stacktrace:

public static void sendErrorReportViaGoogleAnalytics(Exception e) {

    e.printStackTrace();
    Tracker myTracker = EasyTracker.getTracker();
    myTracker.sendException(getDescription(e), false);
}

public static String getDescription(Exception t) {

    final StringBuilder result = new StringBuilder();
    result.append(t.toString());
    result.append(',');
    String oneElement;

    for (StackTraceElement element : t.getStackTrace()) {
        oneElement = element.toString();
        result.append(oneElement);
        result.append(",");
    }

    return result.toString();
}

This works fine, when talking about exceptions, I just call sendErrorReportViaGoogleAnalytics() in the catch part of my exception handling codes, but when it comes to crashes, I only get one line of the stacktrace, like

Binary XML file line #11: Error inflating class fragment

I set

<bool name="ga_reportUncaughtExceptions">true</bool>

in analytics.xml, as I'm using EasyTracker.

What should I do to get the full stacktrace in case of crashes as well?

2条回答
做自己的国王
2楼-- · 2019-03-16 07:50

Just faced with this problem. Simply paste the given code to BaseApplication.onCreate() method of your project or to other place to set the custom ExceptionReporter for uncaught exceptions. And don't forget to declare the given flag in analytics.xml.

<bool name="ga_reportUncaughtExceptions">true</bool>

Custom uncaught exceptions reporter:

ExceptionReporter myHandler =
        new ExceptionReporter(EasyTracker.getInstance(this), GAServiceManager.getInstance(),
                              Thread.getDefaultUncaughtExceptionHandler(), this);

    StandardExceptionParser exceptionParser =
            new StandardExceptionParser(getApplicationContext(), null) {
                    @Override
                    public String getDescription(String threadName, Throwable t) {
                        return "{" + threadName + "} " + Log.getStackTraceString(t);
                    }
                };

    myHandler.setExceptionParser(exceptionParser);

    // Make myHandler the new default uncaught exception handler.
    Thread.setDefaultUncaughtExceptionHandler(myHandler);
查看更多
做自己的国王
3楼-- · 2019-03-16 07:51

Since you didn't describe what you actually did in order to catch the crashes then I can only send you to the docs: https://developers.google.com/analytics/devguides/collection/android/v2/exceptions

If you are using EasyTracker you can declare:

<bool name="ga_reportUncaughtExceptions">true</bool>

otherwise you can implement the ExceptionReporter class as described and attach it to your thread.

查看更多
登录 后发表回答