Search in sources :

Example 26 with JaegerSpan

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

the class UdpSenderTest method testAppendSpanTooLarge.

@Test(expected = SenderException.class)
public void testAppendSpanTooLarge() 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 + 1);
    try {
        sender.append(jaegerSpan);
    } catch (SenderException e) {
        assertEquals(e.getDroppedSpanCount(), 1);
        throw e;
    }
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) Process(io.jaegertracing.thriftjava.Process) SenderException(io.jaegertracing.internal.exceptions.SenderException) Test(org.junit.Test)

Example 27 with JaegerSpan

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

the class V2SpanConverterTest method testSpanDetectsIsClient.

@Test
public void testSpanDetectsIsClient() {
    JaegerSpan span = tracer.buildSpan("test-service-operation").start();
    Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT);
    assertTrue(ConverterUtil.isRpc(span));
    assertTrue(ConverterUtil.isRpcClient(span));
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) Test(org.junit.Test)

Example 28 with JaegerSpan

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

the class JaegerTracerTagsTest method testTracerTags.

@Test
public void testTracerTags() {
    InMemoryReporter spanReporter = new InMemoryReporter();
    JaegerTracer tracer = new JaegerTracer.Builder("x").withReporter(spanReporter).withSampler(new ConstSampler(true)).withZipkinSharedRpcSpan().withTag("tracer.tag.str", "y").build();
    JaegerSpan jaegerSpan = tracer.buildSpan("root").start();
    // span should only contain sampler tags and no tracer tags
    assertEquals(2, jaegerSpan.getTags().size());
    assertEquals(true, jaegerSpan.getTags().containsKey("sampler.type"));
    assertEquals(true, jaegerSpan.getTags().containsKey("sampler.param"));
    assertEquals(false, jaegerSpan.getTags().containsKey("tracer.tag.str"));
}
Also used : InMemoryReporter(io.jaegertracing.internal.reporters.InMemoryReporter) JaegerSpan(io.jaegertracing.internal.JaegerSpan) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Test(org.junit.Test)

Example 29 with JaegerSpan

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

the class UdpSenderTest method buildSpanWithSize.

/**
 * create a mock span with target size
 */
private JaegerSpan buildSpanWithSize(int targetSpanSize) throws Exception {
    JaegerSpan jaegerSpan = tracer.buildSpan("raza").start();
    jaegerSpan.setTag("mock", "");
    // contains mock span tag with empty string value, which is later used to match target span size
    io.jaegertracing.thriftjava.Span emptySpan = JaegerThriftSpanConverter.convertSpan(jaegerSpan);
    int emptySpanSize = sender.getSize(emptySpan);
    int freePacketSizeLeft = targetSpanSize - emptySpanSize;
    // each "0" takes 1 byte in UTF-8
    String mockStr = String.join("", Collections.nCopies(freePacketSizeLeft, "0"));
    jaegerSpan.setTag("mock", mockStr);
    // subtract some chars since the actual encoding takes a few extra bytes
    while (targetSpanSize != sender.getSize(JaegerThriftSpanConverter.convertSpan(jaegerSpan))) {
        mockStr = mockStr.substring(1);
        jaegerSpan.setTag("mock", mockStr);
    }
    return jaegerSpan;
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan)

Example 30 with JaegerSpan

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

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