com.eg.agent.android.harvest.ExceptionMarker Maven / Gradle / Ivy
The newest version!
package com.eg.agent.android.harvest;
import java.text.MessageFormat;
import com.eg.agent.android.harvest.type.ArrayTransformer;
import com.eg.agent.android.logging.EGAgentLog;
import com.eg.agent.android.logging.EGAgentLogManager;
import com.eg.agent.android.stats.StatisticsEngine;
import com.eg.agent.android.Queue;
import com.eg.google.gson.JsonArray;
public class ExceptionMarker extends ArrayTransformer {
public static final String DEFAULT_KEY = "Exception";
private static final EGAgentLog log = EGAgentLogManager.getAgentLog();
protected final ExceptionWrapperMap agentHealthExceptions = new ExceptionWrapperMap();
public static void noticeException(Exception exception) {
ExceptionWrapper agentHealthException = null;
if (exception != null) {
agentHealthException = new ExceptionWrapper(exception);
}
noticeException(agentHealthException);
}
public static void noticeException(ExceptionWrapper exception) {
noticeException(exception, DEFAULT_KEY);
}
public static void noticeException(ExceptionWrapper exception, String key) {
if (exception != null) {
StatisticsEngine statsEngine = StatisticsEngine.get();
if (statsEngine != null) {
if (key == null) {
log.warning("Passed metric key is null. Defaulting to Exception");
}
String str = "Supportability/AgentHealth/{0}/{1}/{2}/{3}";
Object[] objArr = new Object[4];
if (key == null) {
key = DEFAULT_KEY;
}
objArr[0] = key;
objArr[1] = exception.getSourceClass();
objArr[2] = exception.getSourceMethod();
objArr[3] = exception.getExceptionClass();
statsEngine.inc(MessageFormat.format(str, objArr));
Queue.queue(exception);
return;
}
log.error("StatsEngine is null. Exception not recorded.");
return;
}
log.error("AgentHealthException is null. StatsEngine not updated");
}
public void addException(ExceptionWrapper exception) {
this.agentHealthExceptions.add(exception);
}
public void clear() {
this.agentHealthExceptions.clear();
}
public JsonArray asJsonArray() {
JsonArray data = new JsonArray();
if (!this.agentHealthExceptions.isEmpty()) {
data.add(this.agentHealthExceptions.asJsonObject());
}
return data;
}
}