mirror of
https://github.com/angryip/ipscan.git
synced 2025-10-26 11:18:17 +00:00
report first stack frame element to GA in case of unexpected exceptions
This commit is contained in:
parent
3215e7f0f8
commit
80da90fad8
@ -48,7 +48,13 @@ public class GoogleAnalytics {
|
||||
}
|
||||
|
||||
public void report(Throwable e) {
|
||||
report("exception", e.toString());
|
||||
report("exception", extractFirstStackFrame(e));
|
||||
}
|
||||
|
||||
static String extractFirstStackFrame(Throwable e) {
|
||||
StackTraceElement[] stackTrace = e.getStackTrace();
|
||||
return e.toString() + (stackTrace.length == 0 ? "" : "\n" +
|
||||
stackTrace[0].getClassName() + "." + stackTrace[0].getMethodName() + ":" + stackTrace[0].getLineNumber());
|
||||
}
|
||||
|
||||
public void asyncReport(final String screen) {
|
||||
|
||||
14
test/net/azib/ipscan/util/GoogleAnalyticsTest.java
Normal file
14
test/net/azib/ipscan/util/GoogleAnalyticsTest.java
Normal file
@ -0,0 +1,14 @@
|
||||
package net.azib.ipscan.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class GoogleAnalyticsTest {
|
||||
@Test
|
||||
public void extractFirstStackFrame() throws Exception {
|
||||
assertEquals("java.lang.RuntimeException: Kaboom\n" +
|
||||
"net.azib.ipscan.util.GoogleAnalyticsTest.extractFirstStackFrame:10",
|
||||
GoogleAnalytics.extractFirstStackFrame(new RuntimeException("Kaboom")));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user