use of com.twitter.zipkin.thriftjava.Endpoint 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.Endpoint in project jaeger-client-java by jaegertracing.
the class ThriftSpanConverter method convertSpan.
public static com.twitter.zipkin.thriftjava.Span convertSpan(Span span) {
Tracer tracer = span.getTracer();
Endpoint host = new Endpoint(tracer.getIpv4(), (short) 0, tracer.getServiceName());
SpanContext context = span.context();
return new com.twitter.zipkin.thriftjava.Span(context.getTraceId(), span.getOperationName(), context.getSpanId(), buildAnnotations(span, host), buildBinaryAnnotations(span, host)).setParent_id(context.getParentId()).setDebug(context.isDebug()).setTimestamp(span.getStart()).setDuration(span.getDuration());
}
use of com.twitter.zipkin.thriftjava.Endpoint in project jaeger-client-java by jaegertracing.
the class ThriftSpanConverter method buildBinaryAnnotations.
private static List<BinaryAnnotation> buildBinaryAnnotations(Span span, Endpoint host) {
List<BinaryAnnotation> binaryAnnotations = new ArrayList<BinaryAnnotation>();
Map<String, Object> tags = span.getTags();
boolean isRpc = isRpc(span);
boolean isClient = isRpcClient(span);
boolean firstSpanInProcess = span.getReferences().isEmpty() || isRpcServer(span);
if (firstSpanInProcess) {
Map<String, ?> processTags = span.getTracer().tags();
// taken care of separately.
for (Map.Entry<String, ?> entry : processTags.entrySet()) {
String tagKey = entry.getKey();
if (!Constants.TRACER_IP_TAG_KEY.equals(tagKey)) {
Object tagValue = entry.getValue();
// add a tracer. prefix to process tags for zipkin
binaryAnnotations.add(buildBinaryAnnotation("tracer." + tagKey, tagValue));
}
}
}
Endpoint peerEndpoint = extractPeerEndpoint(tags);
if (peerEndpoint != null && isClient) {
String key = isClient ? zipkincoreConstants.SERVER_ADDR : zipkincoreConstants.CLIENT_ADDR;
binaryAnnotations.add(new BinaryAnnotation().setKey(key).setValue(new byte[] { 1 }).setAnnotation_type(AnnotationType.BOOL).setHost(peerEndpoint));
}
if (!isRpc) {
byte[] componentName;
Object componentTag = tags.get(Tags.COMPONENT.getKey());
if (componentTag instanceof String) {
componentName = componentTag.toString().getBytes(UTF_8);
} else {
// spans always have associated tracers, and service names
componentName = span.getTracer().getServiceName().getBytes(UTF_8);
}
binaryAnnotations.add(new BinaryAnnotation().setKey(zipkincoreConstants.LOCAL_COMPONENT).setValue(componentName).setAnnotation_type(AnnotationType.STRING).setHost(host));
}
if (tags != null) {
for (Map.Entry<String, Object> entry : tags.entrySet()) {
String tagKey = entry.getKey();
// Every value is converted to string because zipkin search doesn't
// work well with ints, and bytes.
Object tagValue = entry.getValue();
binaryAnnotations.add(buildBinaryAnnotation(tagKey, tagValue));
}
}
return binaryAnnotations;
}
use of com.twitter.zipkin.thriftjava.Endpoint in project jaeger-client-java by jaegertracing.
the class ThriftSpanConverter method extractPeerEndpoint.
/**
* Extract peer Endpoint from tags
*
* @param tags tags
* @return null or peer endpoint
*/
public static Endpoint extractPeerEndpoint(Map<String, Object> tags) {
Object peerIpv4 = tags.get(Tags.PEER_HOST_IPV4.getKey());
Object peerPort = tags.get(Tags.PEER_PORT.getKey());
Object peerService = tags.get(Tags.PEER_SERVICE.getKey());
if (peerIpv4 == null && peerPort == null && peerService == null) {
return null;
}
Endpoint peerEndpoint = new Endpoint(0, (short) 0, "");
if (peerIpv4 instanceof Integer) {
peerEndpoint.setIpv4((Integer) peerIpv4);
}
if (peerPort instanceof Number) {
peerEndpoint.setPort(((Number) peerPort).shortValue());
}
if (peerService instanceof String) {
peerEndpoint.setService_name((String) peerService);
}
return peerEndpoint;
}
Aggregations