Search in sources :

Example 1 with Batch

use of com.uber.jaeger.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<Span>());
    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.spans.size() >= expectedSpans) {
            return batch;
        }
        Thread.sleep(1);
    }
    return batch;
}
Also used : Batch(com.uber.jaeger.thriftjava.Batch) Span(com.uber.jaeger.thriftjava.Span)

Example 2 with Batch

use of com.uber.jaeger.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;
    Span expectedSpan = (Span) tracer.buildSpan("raza").startManual();
    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());
    com.uber.jaeger.thriftjava.Span actualSpan = batch.getSpans().get(0);
    assertEquals(expectedSpan.context().getTraceId(), actualSpan.getTraceIdLow());
    assertEquals(0, actualSpan.getTraceIdHigh());
    assertEquals(expectedSpan.context().getSpanId(), actualSpan.getSpanId());
    assertEquals(0, actualSpan.getParentSpanId());
    assertTrue(actualSpan.references.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());
}
Also used : Batch(com.uber.jaeger.thriftjava.Batch) Span(com.uber.jaeger.Span) Test(org.junit.Test)

Example 3 with Batch

use of com.uber.jaeger.thriftjava.Batch in project jaeger-client-java by jaegertracing.

the class UdpSenderTest method calculateBatchOverheadDifference.

private int calculateBatchOverheadDifference(int numberOfSpans) throws Exception {
    AutoExpandingBufferWriteTransport memoryTransport = new AutoExpandingBufferWriteTransport(maxPacketSize, 2);
    Agent.Client memoryClient = new Agent.Client(new TCompactProtocol((memoryTransport)));
    Span jaegerSpan = (Span) tracer.buildSpan("raza").startManual();
    com.uber.jaeger.thriftjava.Span span = JaegerThriftSpanConverter.convertSpan(jaegerSpan);
    List<com.uber.jaeger.thriftjava.Span> spans = new ArrayList<>();
    for (int i = 0; i < numberOfSpans; i++) {
        spans.add(span);
    }
    memoryClient.emitBatch(new Batch(new Process(SERVICE_NAME), spans));
    int emitBatchOverheadMultipleSpans = memoryTransport.getPos();
    memoryTransport.reset();
    for (int j = 0; j < numberOfSpans; j++) {
        span.write(new TCompactProtocol(memoryTransport));
    }
    int writeBatchOverheadMultipleSpans = memoryTransport.getPos();
    return emitBatchOverheadMultipleSpans - writeBatchOverheadMultipleSpans;
}
Also used : AutoExpandingBufferWriteTransport(org.apache.thrift.transport.AutoExpandingBufferWriteTransport) Agent(com.uber.jaeger.agent.thrift.Agent) ArrayList(java.util.ArrayList) Process(com.uber.jaeger.thriftjava.Process) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) Span(com.uber.jaeger.Span) Batch(com.uber.jaeger.thriftjava.Batch)

Example 4 with Batch

use of com.uber.jaeger.thriftjava.Batch in project jaeger-client-java by jaegertracing.

the class HttpSender method send.

@Override
public void send(Process process, List<Span> spans) throws TException {
    Batch batch = new Batch(process, spans);
    byte[] bytes = serializer.serialize(batch);
    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 TException(String.format("Could not send %d spans", spans.size()), e);
    }
    if (!response.isSuccessful()) {
        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 TException(exceptionMessage);
    }
}
Also used : Response(okhttp3.Response) TException(org.apache.thrift.TException) Batch(com.uber.jaeger.thriftjava.Batch) Request(okhttp3.Request) IOException(java.io.IOException) ToString(lombok.ToString) RequestBody(okhttp3.RequestBody)

Aggregations

Batch (com.uber.jaeger.thriftjava.Batch)4 Span (com.uber.jaeger.Span)2 Agent (com.uber.jaeger.agent.thrift.Agent)1 Process (com.uber.jaeger.thriftjava.Process)1 Span (com.uber.jaeger.thriftjava.Span)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ToString (lombok.ToString)1 Request (okhttp3.Request)1 RequestBody (okhttp3.RequestBody)1 Response (okhttp3.Response)1 TException (org.apache.thrift.TException)1 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)1 AutoExpandingBufferWriteTransport (org.apache.thrift.transport.AutoExpandingBufferWriteTransport)1 Test (org.junit.Test)1