com.eg.agent.android.instrumentation.okhttp3.CallbackExtension Maven / Gradle / Ivy
package com.eg.agent.android.instrumentation.okhttp3;
/*import com.newrelic.agent.android.TaskQueue;
import com.newrelic.agent.android.api.common.TransactionData;
import com.newrelic.agent.android.instrumentation.TransactionState;
import com.newrelic.agent.android.instrumentation.TransactionStateUtil;
import com.newrelic.agent.android.logging.AgentLog;
import com.newrelic.agent.android.logging.AgentLogManager;
import com.newrelic.agent.android.measurement.http.HttpTransactionMeasurement;*/
import com.eg.agent.android.TaskQueue;
import com.eg.agent.android.common.TransactionData;
import com.eg.agent.android.instrumentation.TransactionState;
import com.eg.agent.android.instrumentation.TransactionStateUtil;
import com.eg.agent.android.logging.AgentLog;
import com.eg.agent.android.logging.AgentLogManager;
import com.eg.agent.android.measurement.http.HttpTransactionMeasurement;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
public class CallbackExtension implements Callback {
private static final AgentLog log = AgentLogManager.getAgentLog();
private Callback impl;
private TransactionState transactionState;
public CallbackExtension(Callback impl, TransactionState transactionState) {
this.impl = impl;
this.transactionState = transactionState;
}
public void onFailure(Call call, IOException e) {
error(e);
this.impl.onFailure(call, e);
}
public void onResponse(Call call, Response response) throws IOException {
this.impl.onResponse(call, checkResponse(response));
}
private Response checkResponse(Response response) {
if (getTransactionState().isComplete()) {
return response;
}
log.debug("CallbackExtension.checkResponse() - transaction is not complete. Inspecting and instrumenting response.");
return OkHttp3TransactionStateUtil.inspectAndInstrumentResponse(getTransactionState(), response);
}
private TransactionState getTransactionState() {
return this.transactionState;
}
private void error(Exception e) {
TransactionState transactionState = getTransactionState();
TransactionStateUtil.setErrorCodeFromException(transactionState, e);
if (!transactionState.isComplete()) {
TransactionData transactionData = transactionState.end();
if (transactionData != null) {
TaskQueue.queue(new HttpTransactionMeasurement(transactionData.getUrl(), transactionData.getHttpMethod(), transactionData.getStatusCode(), transactionData.getErrorCode(), transactionData.getTimestamp(), (double) transactionData.getTime(), transactionData.getBytesSent(), transactionData.getBytesReceived(), transactionData.getAppData()));
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy