use of com.twitter.zipkin.thriftjava.BinaryAnnotation in project jaeger-client-java by jaegertracing.
the class ThriftSpanConverter method buildBinaryAnnotations.
private static List<BinaryAnnotation> buildBinaryAnnotations(JaegerSpan jaegerSpan, Endpoint host) {
List<BinaryAnnotation> binaryAnnotations = new ArrayList<BinaryAnnotation>();
Map<String, Object> tags = jaegerSpan.getTags();
boolean isRpc = ConverterUtil.isRpc(jaegerSpan);
boolean isClient = ConverterUtil.isRpcClient(jaegerSpan);
boolean firstSpanInProcess = jaegerSpan.getReferences().isEmpty() || ConverterUtil.isRpcServer(jaegerSpan);
if (firstSpanInProcess) {
Map<String, ?> processTags = jaegerSpan.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 = jaegerSpan.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.BinaryAnnotation 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);
}
}
}
use of com.twitter.zipkin.thriftjava.BinaryAnnotation 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.BinaryAnnotation in project jaeger-client-java by jaegertracing.
the class ThriftSpanConverter method buildBinaryAnnotation.
private static BinaryAnnotation buildBinaryAnnotation(String tagKey, Object tagValue) {
BinaryAnnotation banno = new BinaryAnnotation().setKey(tagKey);
banno.setValue(String.valueOf(tagValue).getBytes(UTF_8)).setAnnotation_type(AnnotationType.STRING);
return banno;
}
use of com.twitter.zipkin.thriftjava.BinaryAnnotation in project jaeger-client-java by jaegertracing.
the class ThriftSpanConverterTest method testTracerTags.
@Test
@UseDataProvider("dataProviderTracerTags")
public void testTracerTags(SpanType spanType, Map<String, String> expectedTags) throws Exception {
InMemoryReporter spanReporter = new InMemoryReporter();
Tracer tracer = new Tracer.Builder("x", spanReporter, new ConstSampler(true)).withZipkinSharedRpcSpan().withTag("tag.str", "y").withTag("tag.bool", true).withTag("tag.num", 1).build();
Span span = (Span) tracer.buildSpan("root").startManual();
if (spanType == SpanType.CHILD) {
span = (Span) tracer.buildSpan("child").asChildOf(span).startManual();
} else if (spanType == SpanType.RPC_SERVER) {
span = (Span) tracer.buildSpan("rpc-server").asChildOf(span).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).startManual();
}
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);
}
}
}
Aggregations