use of io.jaegertracing.thriftjava.Batch in project jaeger-client-java by jaegertracing.
the class HttpSender method send.
@Override
public void send(Process process, List<Span> spans) throws SenderException {
Batch batch = new Batch(process, spans);
byte[] bytes = null;
try {
bytes = serialize(batch);
} catch (Exception e) {
throw new SenderException(String.format("Failed to serialize %d spans", spans.size()), e, spans.size());
}
RequestBody body = RequestBody.create(MEDIA_TYPE_THRIFT, bytes);
Request request = requestBuilder.post(body).build();
Response response;
try {
response = httpClient.newCall(request).execute();
} catch (IOException e) {
throw new SenderException(String.format("Could not send %d spans", spans.size()), e, spans.size());
}
if (response.isSuccessful()) {
response.close();
return;
}
String responseBody;
try {
responseBody = response.body() != null ? response.body().string() : "null";
} catch (IOException e) {
responseBody = "unable to read response";
}
String exceptionMessage = String.format("Could not send %d spans, response %d: %s", spans.size(), response.code(), responseBody);
throw new SenderException(exceptionMessage, null, spans.size());
}
use of io.jaegertracing.thriftjava.Batch in project jaeger-client-java by jaegertracing.
the class ThriftSenderBaseTest method calculateBatchOverheadDifference.
private int calculateBatchOverheadDifference(int numberOfSpans) throws Exception {
AutoExpandingBufferWriteTransport memoryTransport = new AutoExpandingBufferWriteTransport(new TConfiguration(), maxPacketSize, 2);
Agent.Client memoryClient = new Agent.Client(new TCompactProtocol((memoryTransport)));
Span span = new Span();
span.setOperationName("raza");
// 0, 0, 0, 0, "raza", 0, 0, 0);
List<Span> spans = new ArrayList<>();
for (int i = 0; i < numberOfSpans; i++) {
spans.add(span);
}
memoryClient.emitBatch(new Batch(new io.jaegertracing.thriftjava.Process(SERVICE_NAME), spans));
int emitBatchOverheadMultipleSpans = memoryTransport.getLength();
memoryTransport.reset();
for (int j = 0; j < numberOfSpans; j++) {
span.write(new TCompactProtocol(memoryTransport));
}
int writeBatchOverheadMultipleSpans = memoryTransport.getLength();
return emitBatchOverheadMultipleSpans - writeBatchOverheadMultipleSpans;
}
use of io.jaegertracing.thriftjava.Batch in project jaeger-client-java by jaegertracing.
the class UdpSenderTest method testFlushSendsSpan.
@Test
public void testFlushSendsSpan() throws Exception {
// in milliseconds
int timeout = 50;
int expectedNumSpans = 1;
JaegerSpan expectedSpan = tracer.buildSpan("raza").start();
int appendNum = sender.append(expectedSpan);
int flushNum = sender.flush();
assertEquals(appendNum, 0);
assertEquals(flushNum, 1);
Batch batch = server.getBatch(expectedNumSpans, timeout);
assertEquals(expectedNumSpans, batch.getSpans().size());
io.jaegertracing.thriftjava.Span actualSpan = batch.getSpans().get(0);
assertEquals(expectedSpan.context().getTraceIdLow(), actualSpan.getTraceIdLow());
assertEquals(0, actualSpan.getTraceIdHigh());
assertEquals(expectedSpan.context().getSpanId(), actualSpan.getSpanId());
assertEquals(0, actualSpan.getParentSpanId());
assertTrue(actualSpan.getReferences().isEmpty());
assertEquals(expectedSpan.getOperationName(), actualSpan.getOperationName());
assertEquals(4, batch.getProcess().getTags().size());
assertEquals("hostname", batch.getProcess().getTags().get(0).getKey());
assertEquals("jaeger.version", batch.getProcess().getTags().get(1).getKey());
assertEquals("bar", batch.getProcess().getTags().get(2).getVStr());
assertEquals("ip", batch.getProcess().getTags().get(3).getKey());
}
use of io.jaegertracing.thriftjava.Batch in project jaeger-client-java by jaegertracing.
the class UdpSenderTest method testFlushSendsSpanWith128BitTraceId.
@Test
public void testFlushSendsSpanWith128BitTraceId() throws Exception {
// in milliseconds
int timeout = 50;
int expectedNumSpans = 1;
JaegerSpan expectedSpan = tracer128.buildSpan("raza").start();
assertEquals(0, sender.append(expectedSpan));
assertEquals(1, sender.flush());
Batch batch = server.getBatch(expectedNumSpans, timeout);
assertEquals(expectedNumSpans, batch.getSpans().size());
io.jaegertracing.thriftjava.Span actualSpan = batch.getSpans().get(0);
assertEquals(expectedSpan.context().getTraceIdLow(), actualSpan.getTraceIdLow());
assertEquals(expectedSpan.context().getTraceIdHigh(), actualSpan.getTraceIdHigh());
}
use of io.jaegertracing.thriftjava.Batch in project jaeger-client-java by jaegertracing.
the class TestTServer method getBatch.
public Batch getBatch(int expectedSpans, int timeout) throws Exception {
Batch batch = new Batch().setSpans(new ArrayList<>());
long expire = timeout + System.currentTimeMillis();
while (System.currentTimeMillis() < expire) {
Batch receivedBatch = handler.getBatch();
if (receivedBatch.getSpans() != null) {
batch.getSpans().addAll(receivedBatch.getSpans());
batch.setProcess(receivedBatch.getProcess());
}
if (batch.getSpans().size() >= expectedSpans) {
return batch;
}
Thread.sleep(1);
}
return batch;
}
Aggregations