Track dropped transactions
@@ -7,14 +7,16 @@ import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import okio.BufferedSink;
+import okio.GzipSink;
+import okio.Okio;
import java.io.IOException;
public class ApmServerHttpPayloadSender implements PayloadSender {
- public static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json");
private final OkHttpClient httpClient;
private final ReporterConfiguration reporterConfiguration;
private final PayloadRequestBody body;
+ private long droppedTransactions = 0;
public ApmServerHttpPayloadSender(OkHttpClient httpClient, PayloadSerializer payloadSerializer,
ReporterConfiguration reporterConfiguration) {
@@ -35,15 +37,22 @@ public class ApmServerHttpPayloadSender implements PayloadSender {
try {
httpClient.newCall(request).execute();
} catch (IOException e) {
- e.printStackTrace();
+ droppedTransactions += payload.getTransactions().size();
}
}
+ public long getDroppedTransactions() {
+ return droppedTransactions;
+ }
+
private static class PayloadRequestBody extends RequestBody {
+ private static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json");
+
private final PayloadSerializer payloadSerializer;
+
TransactionPayload payload;
- public PayloadRequestBody(PayloadSerializer payloadSerializer) {
+ PayloadRequestBody(PayloadSerializer payloadSerializer) {
this.payloadSerializer = payloadSerializer;
}
@@ -54,7 +63,7 @@ public class ApmServerHttpPayloadSender implements PayloadSender {
@Override
public void writeTo(BufferedSink sink) throws IOException {
- payloadSerializer.serializePayload(sink, payload);
+ payloadSerializer.serializePayload(Okio.buffer(new GzipSink(sink)), payload);
sink.close();
for (Transaction transaction : payload.getTransactions()) {
transaction.recycle();
