com.eg.agent.android.instrumentation.okhttp2.CallExtension Maven / Gradle / Ivy
package com.eg.agent.android.instrumentation.okhttp2;
/*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 com.squareup.okhttp.Call;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import java.io.IOException;
public class CallExtension extends Call {
private static final AgentLog log = AgentLogManager.getAgentLog();
private OkHttpClient client;
private Call impl;
private Request request;
private TransactionState transactionState;
CallExtension(OkHttpClient client, Request request, Call impl) {
super(client, request);
this.client = client;
this.request = request;
this.impl = impl;
}
public Response execute() throws IOException {
getTransactionState();
try {
return checkResponse(this.impl.execute());
} catch (IOException e) {
error(e);
throw e;
}
}
public void enqueue(Callback responseCallback) {
getTransactionState();
this.impl.enqueue(new CallbackExtension(responseCallback, this.transactionState));
}
public void cancel() {
this.impl.cancel();
}
public boolean isCanceled() {
return this.impl.isCanceled();
}
private Response checkResponse(Response response) {
if (getTransactionState().isComplete()) {
return response;
}
return OkHttp2TransactionStateUtil.inspectAndInstrumentResponse(getTransactionState(), response);
}
private TransactionState getTransactionState() {
if (this.transactionState == null) {
this.transactionState = new TransactionState();
OkHttp2TransactionStateUtil.inspectAndInstrument(this.transactionState, this.request);
}
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