Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google analytics crash report only shows first line of stacktrace

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?

like image 949
Analizer Avatar asked Apr 16 '13 09:04

Analizer


2 Answers

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);
like image 139
sky Avatar answered Oct 20 '22 21:10

sky


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.

like image 38
Raanan Avatar answered Oct 20 '22 19:10

Raanan