Search in sources :

Example 11 with JaegerSpan

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

the class ZipkinSenderTest method testAppend128BitTraceId.

@Test
public void testAppend128BitTraceId() throws Exception {
    JaegerSpan expectedSpan = tracer128.buildSpan("raza").start();
    sender.append(expectedSpan);
    sender.flush();
    List<List<zipkin2.Span>> traces = zipkinRule.getTraces();
    assertEquals(traces.size(), 1);
    assertEquals(traces.get(0).size(), 1);
    zipkin2.Span actualSpan = traces.get(0).get(0);
    JaegerSpanContext context = expectedSpan.context();
    assertNotEquals(context.getTraceIdHigh(), 0L);
    assertTrue(actualSpan.traceId().length() > 16);
    assertEquals(context.getTraceIdLow(), HexCodec.lowerHexToUnsignedLong(actualSpan.traceId()));
    assertEquals(context.getTraceIdHigh(), HexCodec.lowerHexToUnsignedLong(actualSpan.traceId().substring(0, 16)));
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) ArrayList(java.util.ArrayList) List(java.util.List) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 12 with JaegerSpan

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

the class ThriftSpanConverterTest method testSpanDetectsIsServer.

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

Example 13 with JaegerSpan

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

the class ThriftSpanConverterTest method testTracerTags.

@Test
@UseDataProvider("dataProviderTracerTags")
public void testTracerTags(SpanType spanType, Map<String, String> expectedTags) {
    InMemoryReporter spanReporter = new InMemoryReporter();
    JaegerTracer tracer = new JaegerTracer.Builder("x").withReporter(spanReporter).withSampler(new ConstSampler(true)).withZipkinSharedRpcSpan().withTag("tag.str", "y").withTag("tag.bool", true).withTag("tag.num", 1).build();
    JaegerSpan span = tracer.buildSpan("root").start();
    if (spanType == SpanType.CHILD) {
        span = tracer.buildSpan("child").asChildOf(span).start();
    } else if (spanType == SpanType.RPC_SERVER) {
        span = tracer.buildSpan("rpc-server").asChildOf(span).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).start();
    }
    com.twitter.zipkin.thriftjava.Span zipkinSpan = ThriftSpanConverter.convertSpan(span);
    List<BinaryAnnotation> annotations = zipkinSpan.getBinary_annotations();
    for (Map.Entry<String, String> entry : expectedTags.entrySet()) {
        String key = entry.getKey();
        Object expectedValue = entry.getValue();
        BinaryAnnotation anno = findBinaryAnnotation(annotations, key);
        if (expectedValue.equals(UNDEF)) {
            assertNull("Not expecting " + key + " for " + spanType, anno);
        } else if (expectedValue.equals(ANY)) {
            assertEquals(key, anno.getKey());
        } else {
            String actualValue = new String(anno.getValue(), StandardCharsets.UTF_8);
            assertEquals("Expecting " + key + " for " + spanType, expectedValue, actualValue);
        }
    }
}
Also used : InMemoryReporter(io.jaegertracing.internal.reporters.InMemoryReporter) BinaryAnnotation(com.twitter.zipkin.thriftjava.BinaryAnnotation) JaegerSpan(io.jaegertracing.internal.JaegerSpan) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) HashMap(java.util.HashMap) Map(java.util.Map) TextMap(io.opentracing.propagation.TextMap) TreeMap(java.util.TreeMap) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 14 with JaegerSpan

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

the class ThriftSpanConverterTest method testExpectedLocalComponentNameUsed.

@Test
public void testExpectedLocalComponentNameUsed() {
    String expectedComponentName = "local-name";
    JaegerSpan span = tracer.buildSpan("operation-name").start();
    Tags.COMPONENT.set(span, expectedComponentName);
    com.twitter.zipkin.thriftjava.Span zipkinSpan = ThriftSpanConverter.convertSpan(span);
    String actualComponent = new String(zipkinSpan.getBinary_annotations().get(3).getValue(), StandardCharsets.UTF_8);
    assertEquals(expectedComponentName, actualComponent);
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) Test(org.junit.Test)

Example 15 with JaegerSpan

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

the class ThriftSpanConverterTest method testSpanKindClientCreatesAnnotations.

@Test
public void testSpanKindClientCreatesAnnotations() {
    JaegerSpan span = tracer.buildSpan("operation-name").start();
    Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_CLIENT);
    com.twitter.zipkin.thriftjava.Span zipkinSpan = ThriftSpanConverter.convertSpan(span);
    List<Annotation> annotations = zipkinSpan.getAnnotations();
    boolean clientReceiveFound = false;
    boolean clientSendFound = false;
    for (Annotation anno : annotations) {
        if (anno.getValue().equals(zipkincoreConstants.CLIENT_RECV)) {
            clientReceiveFound = true;
        }
        if (anno.getValue().equals(zipkincoreConstants.CLIENT_SEND)) {
            clientSendFound = true;
        }
    }
    assertTrue(clientReceiveFound);
    assertTrue(clientSendFound);
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) BinaryAnnotation(com.twitter.zipkin.thriftjava.BinaryAnnotation) Annotation(com.twitter.zipkin.thriftjava.Annotation) 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