Search in sources :

Example 31 with JaegerSpan

use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.

the class UdpSenderTest method testAppendMaxSize.

@Test
public void testAppendMaxSize() throws Exception {
    Process process = new Process(tracer.getServiceName()).setTags(JaegerThriftSpanConverter.buildTags(tracer.tags()));
    int processSize = sender.getSize(process);
    JaegerSpan jaegerSpan = buildSpanWithSize(maxPacketSize - UdpSender.EMIT_BATCH_OVERHEAD - processSize);
    int result = sender.append(jaegerSpan);
    assertEquals(1, result);
    // test if the buffer is reinitialized correctly
    result = sender.append(jaegerSpan);
    assertEquals(1, result);
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) Process(io.jaegertracing.thriftjava.Process) Test(org.junit.Test)

Example 32 with JaegerSpan

use of io.jaegertracing.internal.JaegerSpan 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 33 with JaegerSpan

use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.

the class UdpSenderTest method testAppend.

@Test
public void testAppend() throws Exception {
    // find size of the initial span
    JaegerSpan jaegerSpan = tracer.buildSpan("raza").start();
    io.jaegertracing.thriftjava.Span span = JaegerThriftSpanConverter.convertSpan(jaegerSpan);
    Process process = new Process(tracer.getServiceName()).setTags(JaegerThriftSpanConverter.buildTags(tracer.tags()));
    int processSize = sender.getSize(process);
    int spanSize = sender.getSize(span);
    // create a sender thats a multiple of the span size (accounting for span overhead)
    // this allows us to test the boundary conditions of writing spans.
    int expectedNumSpans = 11;
    int maxPacketSize = (spanSize * expectedNumSpans) + UdpSender.EMIT_BATCH_OVERHEAD + processSize;
    int maxPacketSizeLeft = maxPacketSize - UdpSender.EMIT_BATCH_OVERHEAD - processSize;
    // add enough spans to be under buffer limit
    sender = new UdpSender(destHost, destPort, maxPacketSize);
    while (spanSize < maxPacketSizeLeft) {
        sender.append(jaegerSpan);
        maxPacketSizeLeft -= spanSize;
    }
    // add a span that overflows the limit to hit the last branch
    int result = sender.append(jaegerSpan);
    assertEquals(expectedNumSpans, result);
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) Process(io.jaegertracing.thriftjava.Process) Test(org.junit.Test)

Example 34 with JaegerSpan

use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.

the class V2SpanConverter method convertSpan.

public static zipkin2.Span convertSpan(JaegerSpan span) {
    JaegerTracer tracer = span.getTracer();
    zipkin2.Endpoint.Builder host = zipkin2.Endpoint.newBuilder().serviceName(tracer.getServiceName());
    if (tracer.getIpv4() != 0) {
        host.parseIp(convertIp(tracer.getIpv4()));
    }
    zipkin2.Endpoint peerEndpoint = extractPeerEndpoint(span.getTags());
    JaegerSpanContext context = span.context();
    zipkin2.Span.Builder builder = zipkin2.Span.newBuilder().id(Long.toHexString(context.getSpanId())).traceId(context.getTraceIdHigh(), context.getTraceIdLow()).name(span.getOperationName()).parentId(Long.toHexString(context.getParentId())).debug(context.isDebug()).localEndpoint(host.build()).remoteEndpoint(peerEndpoint).kind(convertKind(span.getTags().get(Tags.SPAN_KIND.getKey()))).timestamp(span.getStart()).duration(span.getDuration());
    buildAnnotations(span, builder);
    buildTags(span, builder);
    return builder.build();
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) JaegerTracer(io.jaegertracing.internal.JaegerTracer) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext)

Example 35 with JaegerSpan

use of io.jaegertracing.internal.JaegerSpan in project jaeger-client-java by jaegertracing.

the class ZipkinSenderTest method testAppendSpanTooLarge.

@Test
public void testAppendSpanTooLarge() {
    JaegerSpan jaegerSpan = tracer.buildSpan("raza").start();
    String msg = "";
    for (int i = 0; i < 1001; i++) {
        msg += ".";
    }
    jaegerSpan.log(msg);
    try {
        sender.append(jaegerSpan);
        fail("The line above shoud throw");
    } catch (SenderException e) {
        assertEquals(e.getDroppedSpanCount(), 1);
    }
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) SenderException(io.jaegertracing.internal.exceptions.SenderException) Test(org.junit.Test)

Aggregations

JaegerSpan (io.jaegertracing.internal.JaegerSpan)51 Test (org.junit.Test)47 JaegerSpanContext (io.jaegertracing.internal.JaegerSpanContext)10 HashMap (java.util.HashMap)8 JaegerTracer (io.jaegertracing.internal.JaegerTracer)7 InMemoryReporter (io.jaegertracing.internal.reporters.InMemoryReporter)7 ConstSampler (io.jaegertracing.internal.samplers.ConstSampler)6 ArrayList (java.util.ArrayList)6 TreeMap (java.util.TreeMap)5 BinaryAnnotation (com.twitter.zipkin.thriftjava.BinaryAnnotation)4 SenderException (io.jaegertracing.internal.exceptions.SenderException)4 TextMap (io.opentracing.propagation.TextMap)4 TextMapAdapter (io.opentracing.propagation.TextMapAdapter)4 List (java.util.List)4 Annotation (com.twitter.zipkin.thriftjava.Annotation)3 Process (io.jaegertracing.thriftjava.Process)3 Map (java.util.Map)3 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 Builder (io.jaegertracing.internal.reporters.RemoteReporter.Builder)2 InMemorySender (io.jaegertracing.internal.senders.InMemorySender)2