Search in sources :

Example 36 with JaegerSpan

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

the class ZipkinSenderTest method testAppendSpanWithLogs.

@Test
public void testAppendSpanWithLogs() throws Exception {
    JaegerSpan jaegerSpan = tracer.buildSpan("jaegerSpan-with-logs").start();
    jaegerSpan.log("event");
    // use sorted map for consistent ordering in test
    Map<String, Object> fields = new TreeMap<String, Object>();
    fields.put("event", "structured data");
    fields.put("string", "something");
    fields.put("number", 42);
    fields.put("boolean", true);
    jaegerSpan.log(fields);
    sender.append(jaegerSpan);
    sender.flush();
    List<List<zipkin2.Span>> traces = zipkinRule.getTraces();
    assertEquals(1, traces.size());
    assertEquals(1, traces.get(0).size());
    zipkin2.Span zipkinSpan = traces.get(0).get(0);
    assertEquals(2, zipkinSpan.annotations().size());
    // ignore order by using set
    Set<String> annotationValues = new HashSet<String>();
    for (Annotation annotation : zipkinSpan.annotations()) {
        annotationValues.add(annotation.value());
    }
    Set<String> expectedValues = new HashSet<String>();
    expectedValues.add("event");
    expectedValues.add("{\"boolean\":true,\"event\":\"structured data\",\"number\":42,\"string\":\"something\"}");
    assertEquals("zipkin span should contain matching annotations for span logs", expectedValues, annotationValues);
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) Annotation(zipkin2.Annotation) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 37 with JaegerSpan

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

the class ThriftSpanConverterTest method testRpcChildSpanHasTheSameId.

@Test
public void testRpcChildSpanHasTheSameId() {
    String expectedOperation = "parent";
    JaegerSpan client = tracer.buildSpan(expectedOperation).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).start();
    Map<String, String> map = new HashMap<>();
    TextMap carrier = new TextMapAdapter(map);
    tracer.inject(client.context(), Format.Builtin.TEXT_MAP, carrier);
    JaegerSpanContext ctx = tracer.extract(Format.Builtin.TEXT_MAP, carrier);
    JaegerSpanContext clientCtx = client.context();
    assertEquals(clientCtx.getSpanId(), ctx.getSpanId());
    JaegerSpan server = tracer.buildSpan("child").withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).asChildOf(ctx).start();
    JaegerSpanContext serverCtx = server.context();
    assertEquals("client and server must have the same span ID", clientCtx.getSpanId(), serverCtx.getSpanId());
}
Also used : HashMap(java.util.HashMap) JaegerSpan(io.jaegertracing.internal.JaegerSpan) TextMap(io.opentracing.propagation.TextMap) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 38 with JaegerSpan

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

the class ThriftSpanConverterTest method testConvertSpanWith128BitTraceId.

@Test
public void testConvertSpanWith128BitTraceId() {
    JaegerSpan span = tracer128.buildSpan("operation-name").start();
    com.twitter.zipkin.thriftjava.Span zipkinSpan = ThriftSpanConverter.convertSpan(span);
    assertNotEquals(0, span.context().getTraceIdHigh());
    assertEquals(span.context().getTraceIdLow(), zipkinSpan.getTrace_id());
    assertEquals(span.context().getTraceIdHigh(), zipkinSpan.getTrace_id_high());
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) Test(org.junit.Test)

Example 39 with JaegerSpan

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

the class ThriftSpanConverterTest method testSpanKindServerCreatesAnnotations.

@Test
public void testSpanKindServerCreatesAnnotations() {
    JaegerSpan span = tracer.buildSpan("operation-name").start();
    Tags.SPAN_KIND.set(span, Tags.SPAN_KIND_SERVER);
    com.twitter.zipkin.thriftjava.Span zipkinSpan = ThriftSpanConverter.convertSpan(span);
    List<Annotation> annotations = zipkinSpan.getAnnotations();
    boolean serverReceiveFound = false;
    boolean serverSendFound = false;
    for (Annotation anno : annotations) {
        if (anno.getValue().equals(zipkincoreConstants.SERVER_RECV)) {
            serverReceiveFound = true;
        }
        if (anno.getValue().equals(zipkincoreConstants.SERVER_SEND)) {
            serverSendFound = true;
        }
    }
    assertTrue(serverReceiveFound);
    assertTrue(serverSendFound);
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) BinaryAnnotation(com.twitter.zipkin.thriftjava.BinaryAnnotation) Annotation(com.twitter.zipkin.thriftjava.Annotation) Test(org.junit.Test)

Example 40 with JaegerSpan

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

the class ThriftSpanConverterTest method testSpanLogsCreateAnnotations.

@Test
public void testSpanLogsCreateAnnotations() {
    JaegerSpan span = tracer.buildSpan("span-with-logs").start();
    span.log("event");
    // use sorted map for consistent ordering in test
    Map<String, Object> fields = new TreeMap<String, Object>();
    fields.put("event", "structured data");
    fields.put("string", "something");
    fields.put("number", 42);
    fields.put("boolean", true);
    span.log(fields);
    com.twitter.zipkin.thriftjava.Span zipkinSpan = ThriftSpanConverter.convertSpan(span);
    List<String> annotationValues = new ArrayList<String>();
    for (Annotation annotation : zipkinSpan.getAnnotations()) {
        annotationValues.add(annotation.getValue());
    }
    List<String> expectedValues = new ArrayList<String>();
    expectedValues.add("event");
    expectedValues.add("{\"boolean\":true,\"event\":\"structured data\",\"number\":42,\"string\":\"something\"}");
    assertEquals("zipkin span should contain matching annotations for span logs", expectedValues, annotationValues);
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) 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