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);
}
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());
}
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());
}
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);
}
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);
}
Aggregations