Search in sources :

Example 1 with Batch

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());
}
Also used : Response(okhttp3.Response) Batch(io.jaegertracing.thriftjava.Batch) Request(okhttp3.Request) IOException(java.io.IOException) ToString(lombok.ToString) SenderException(io.jaegertracing.internal.exceptions.SenderException) TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException) SenderException(io.jaegertracing.internal.exceptions.SenderException) RequestBody(okhttp3.RequestBody)

Example 2 with Batch

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;
}
Also used : AutoExpandingBufferWriteTransport(org.apache.thrift.transport.AutoExpandingBufferWriteTransport) Agent(io.jaegertracing.agent.thrift.Agent) ArrayList(java.util.ArrayList) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) Span(io.jaegertracing.thriftjava.Span) Batch(io.jaegertracing.thriftjava.Batch) TConfiguration(org.apache.thrift.TConfiguration)

Example 3 with Batch

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());
}
Also used : Batch(io.jaegertracing.thriftjava.Batch) JaegerSpan(io.jaegertracing.internal.JaegerSpan) Test(org.junit.Test)

Example 4 with Batch

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());
}
Also used : Batch(io.jaegertracing.thriftjava.Batch) JaegerSpan(io.jaegertracing.internal.JaegerSpan) Test(org.junit.Test)

Example 5 with Batch

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;
}
Also used : Batch(io.jaegertracing.thriftjava.Batch)

Aggregations

Batch (io.jaegertracing.thriftjava.Batch)5 JaegerSpan (io.jaegertracing.internal.JaegerSpan)2 Test (org.junit.Test)2 Agent (io.jaegertracing.agent.thrift.Agent)1 SenderException (io.jaegertracing.internal.exceptions.SenderException)1 Span (io.jaegertracing.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 TConfiguration (org.apache.thrift.TConfiguration)1 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)1 AutoExpandingBufferWriteTransport (org.apache.thrift.transport.AutoExpandingBufferWriteTransport)1 TTransportException (org.apache.thrift.transport.TTransportException)1