use of com.twitter.zipkin.thriftjava.Annotation in project zipkin by openzipkin.
the class ThriftCodecInteropTest method spanSerializationIsCompatible.
@Test
public void spanSerializationIsCompatible() throws UnknownHostException, TException {
zipkin.Endpoint zipkinEndpoint = zipkin.Endpoint.builder().serviceName("web").ipv4(124 << 24 | 13 << 16 | 90 << 8 | 3).ipv6(Inet6Address.getByName("2001:db8::c001").getAddress()).port((short) 80).build();
zipkin.Span zipkinSpan = zipkin.Span.builder().traceId(1L).traceIdHigh(2L).id(1L).name("get").addAnnotation(zipkin.Annotation.create(1000, SERVER_RECV, zipkinEndpoint)).addAnnotation(zipkin.Annotation.create(1350, SERVER_SEND, zipkinEndpoint)).build();
Endpoint thriftEndpoint = new Endpoint().setService_name("web").setIpv4(124 << 24 | 13 << 16 | 90 << 8 | 3).setIpv6(Inet6Address.getByName("2001:db8::c001").getAddress()).setPort((short) 80);
Span thriftSpan = new Span(1L, "get", 1L, asList(new Annotation(1000, SERVER_RECV).setHost(thriftEndpoint), new Annotation(1350, SERVER_SEND).setHost(thriftEndpoint)), asList()).setTrace_id_high(2L);
assertThat(serializer.serialize(thriftSpan)).isEqualTo(Codec.THRIFT.writeSpan(zipkinSpan));
assertThat(Codec.THRIFT.writeSpan(zipkinSpan)).isEqualTo(serializer.serialize(thriftSpan));
Span deserializedThrift = new Span();
deserializer.deserialize(deserializedThrift, Codec.THRIFT.writeSpan(zipkinSpan));
assertThat(deserializedThrift).isEqualTo(thriftSpan);
assertThat(Codec.THRIFT.readSpan(serializer.serialize(thriftSpan))).isEqualTo(zipkinSpan);
}
use of com.twitter.zipkin.thriftjava.Annotation in project jaeger-client-java by jaegertracing.
the class ThriftSpanConverter method buildAnnotations.
private static List<Annotation> buildAnnotations(Span span, Endpoint host) {
List<Annotation> annotations = new ArrayList<Annotation>();
if (isRpc(span)) {
String startLabel = zipkincoreConstants.SERVER_RECV;
String endLabel = zipkincoreConstants.SERVER_SEND;
if (isRpcClient(span)) {
startLabel = zipkincoreConstants.CLIENT_SEND;
endLabel = zipkincoreConstants.CLIENT_RECV;
}
annotations.add(new Annotation(span.getStart(), startLabel).setHost(host));
annotations.add(new Annotation(span.getStart() + span.getDuration(), endLabel).setHost(host));
}
List<LogData> logs = span.getLogs();
if (logs != null) {
for (LogData logData : logs) {
String logMessage = logData.getMessage();
Map<String, ?> logFields = logData.getFields();
if (logMessage != null) {
annotations.add(new Annotation(logData.getTime(), logMessage));
} else if (logFields != null) {
annotations.add(new Annotation(logData.getTime(), gson.toJson(logFields)));
}
}
}
return annotations;
}
use of com.twitter.zipkin.thriftjava.Annotation in project jaeger-client-java by jaegertracing.
the class ThriftSpanConverterTest method testSpanKindServerCreatesAnnotations.
@Test
public void testSpanKindServerCreatesAnnotations() {
Span span = (com.uber.jaeger.Span) tracer.buildSpan("operation-name").startManual();
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 com.twitter.zipkin.thriftjava.Annotation in project jaeger-client-java by jaegertracing.
the class ThriftSpanConverterTest method testSpanLogsCreateAnnotations.
@Test
public void testSpanLogsCreateAnnotations() {
Span span = (com.uber.jaeger.Span) tracer.buildSpan("span-with-logs").startManual();
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);
}
use of com.twitter.zipkin.thriftjava.Annotation in project jaeger-client-java by jaegertracing.
the class ThriftSpanConverterTest method testSpanKindClientCreatesAnnotations.
@Test
public void testSpanKindClientCreatesAnnotations() {
Span span = (com.uber.jaeger.Span) tracer.buildSpan("operation-name").startManual();
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);
}
Aggregations