SpansByParent(Collection<Span> spans) { TreeSet<Span> treeSet = new TreeSet<Span>(COMPARATOR); parentToSpans = new HashMap<SpanId, LinkedList<Span>>(); for (Span span : spans) { treeSet.add(span); for (SpanId parent : span.getParents()) { LinkedList<Span> list = parentToSpans.get(parent); if (list == null) { list = new LinkedList<Span>(); parentToSpans.put(parent, list); } list.add(span); } if (span.getParents().length == 0) { LinkedList<Span> list = parentToSpans.get(SpanId.INVALID); if (list == null) { list = new LinkedList<Span>(); parentToSpans.put(SpanId.INVALID, list); } list.add(span); } } this.treeSet = treeSet; }
@Override public SpanId call() throws Exception { return Tracer.getCurrentSpan().getParents()[0]; } }, "child");
SpansByParent(Collection<Span> spans) { TreeSet<Span> treeSet = new TreeSet<Span>(COMPARATOR); parentToSpans = new HashMap<SpanId, LinkedList<Span>>(); for (Span span : spans) { treeSet.add(span); for (SpanId parent : span.getParents()) { LinkedList<Span> list = parentToSpans.get(parent); if (list == null) { list = new LinkedList<Span>(); parentToSpans.put(parent, list); } list.add(span); } if (span.getParents().length == 0) { LinkedList<Span> list = parentToSpans.get(SpanId.INVALID); if (list == null) { list = new LinkedList<Span>(); parentToSpans.put(SpanId.INVALID, list); } list.add(span); } } this.treeSet = treeSet; }
SpansByParent(Collection<Span> spans) { TreeSet<Span> treeSet = new TreeSet<Span>(COMPARATOR); parentToSpans = new HashMap<SpanId, LinkedList<Span>>(); for (Span span : spans) { treeSet.add(span); for (SpanId parent : span.getParents()) { LinkedList<Span> list = parentToSpans.get(parent); if (list == null) { list = new LinkedList<Span>(); parentToSpans.put(parent, list); } list.add(span); } if (span.getParents().length == 0) { LinkedList<Span> list = parentToSpans.get(SpanId.INVALID); if (list == null) { list = new LinkedList<Span>(); parentToSpans.put(SpanId.INVALID, list); } list.add(span); } } this.treeSet = treeSet; }
/** * Converts a given HTrace span to a Zipkin Span. * <ul> * <li>First set the start annotation. [CS, SR], depending whether it is a client service or not. * <li>Set other id's, etc [TraceId's etc] * <li>Create binary annotations based on data from HTrace Span object. * <li>Set the last annotation. [SS, CR] * </ul> */ public Span convert(org.apache.htrace.core.Span hTraceSpan) { Span zipkinSpan = new Span(); String serviceName = hTraceSpan.getTracerId().toLowerCase(); Endpoint ep = new Endpoint(ipv4Address, (short) getPort(serviceName), serviceName); List<Annotation> annotationList = createZipkinAnnotations(hTraceSpan, ep); List<BinaryAnnotation> binaryAnnotationList = createZipkinBinaryAnnotations(hTraceSpan, ep); zipkinSpan.setTrace_id(hTraceSpan.getSpanId().getHigh()); if (hTraceSpan.getParents().length > 0) { if (hTraceSpan.getParents().length > 1) { LOG.error("zipkin doesn't support spans with multiple parents. Omitting " + "other parents for " + hTraceSpan); } zipkinSpan.setParent_id(hTraceSpan.getParents()[0].getLow()); } zipkinSpan.setId(hTraceSpan.getSpanId().getLow()); zipkinSpan.setName(hTraceSpan.getDescription()); zipkinSpan.setAnnotations(annotationList); zipkinSpan.setBinary_annotations(binaryAnnotationList); return zipkinSpan; }
/** * Converts a given HTrace span to a Zipkin Span. * <ul> * <li>First set the start annotation. [CS, SR], depending whether it is a client service or not. * <li>Set other id's, etc [TraceId's etc] * <li>Create binary annotations based on data from HTrace Span object. * <li>Set the last annotation. [SS, CR] * </ul> */ public Span convert(org.apache.htrace.core.Span hTraceSpan) { Span zipkinSpan = new Span(); String serviceName = hTraceSpan.getTracerId().toLowerCase(); Endpoint ep = new Endpoint(ipv4Address, (short) getPort(serviceName), serviceName); List<Annotation> annotationList = createZipkinAnnotations(hTraceSpan, ep); List<BinaryAnnotation> binaryAnnotationList = createZipkinBinaryAnnotations(hTraceSpan, ep); zipkinSpan.setTrace_id(hTraceSpan.getSpanId().getHigh()); if (hTraceSpan.getParents().length > 0) { if (hTraceSpan.getParents().length > 1) { LOG.error("zipkin doesn't support spans with multiple parents. Omitting " + "other parents for " + hTraceSpan); } zipkinSpan.setParent_id(hTraceSpan.getParents()[0].getLow()); } zipkinSpan.setId(hTraceSpan.getSpanId().getLow()); zipkinSpan.setName(hTraceSpan.getDescription()); zipkinSpan.setAnnotations(annotationList); zipkinSpan.setBinary_annotations(binaryAnnotationList); return zipkinSpan; }
private void assertSpansAreEquivalent(Span s, com.twitter.zipkin.gen.Span zs) { assertTrue("zipkin doesn't support multiple parents to a single span.", s.getParents().length <= 1); if (s.getParents().length == 1) { assertEquals(s.getParents()[0].getLow(), zs.getParent_id()); } assertEquals(s.getSpanId().getLow(), zs.getId()); Assert.assertNotNull(zs.getAnnotations()); if (ROOT_SPAN_DESC.equals(zs.getName())) { assertEquals(5, zs.getAnnotations().size());// two start, two stop + one timeline annotation assertEquals(1, zs.getBinary_annotations().size()); } else { assertEquals(4, zs.getAnnotations().size()); } } }
.setDescription(span.getDescription()); if (span.getParents().length == 0) { sbuilder.setParentId(0); } else if (span.getParents().length > 0) { sbuilder.setParentId(span.getParents()[0].getLow()); if (span.getParents().length > 1) { LOG.error("error: HBaseSpanReceiver does not support spans " + "with multiple parents. Ignoring multiple parents for " + if (span.getParents().length == 0) { put.addColumn(HBaseSpanReceiver.this.icf, INDEX_TIME_QUAL, Bytes.toBytes(span.getStartTimeMillis()));
newScope("ChildScope", parentID); Assert.assertNotNull(childScope); Assert.assertEquals(childScope.getSpan().getParents().length, 2); Assert.assertNotNull(spanIdHashMap.get(childScope.getSpan().getParents()[0].hashCode())); Assert.assertEquals(childScope.getSpan().getParents()[0].getHigh(), spanIdHashMap.get(childScope.getSpan().getParents()[0].hashCode()).getHigh()); Assert.assertEquals(childScope.getSpan().getParents()[0].getLow(), spanIdHashMap.get(childScope.getSpan().getParents()[0].hashCode()).getLow()); Assert.assertNotNull(spanIdHashMap.get(childScope.getSpan().getParents()[1].hashCode())); Assert.assertEquals(childScope.getSpan().getParents()[1].getHigh(), spanIdHashMap.get(childScope.getSpan().getParents()[1].hashCode()).getHigh()); Assert.assertEquals(childScope.getSpan().getParents()[1].getLow(), spanIdHashMap.get(childScope.getSpan().getParents()[1].hashCode()).getLow()); childScope.close(); activeScope.close();
for (SpanId parent : span.getParents()) { jgen.writeString(parent.toString());
for (SpanId parent : span.getParents()) { jgen.writeString(parent.toString());
spanRow.addLong(column_span_stop_time, span.getStopTimeMillis()); spanRow.addLong(column_span_span_id, span.getSpanId().getHigh()); if (span.getParents().length == 0) { spanRow.addBoolean(column_span_parent, true); } else if (span.getParents().length > 0) { for (int i = 0; i < span.getParents().length; i++) { Insert parentInsert = tableParent.newInsert(); PartialRow parentRow = parentInsert.getRow(); parentRow.addLong(column_parent_id_low, span.getParents()[i].getLow()); parentRow.addLong(column_parent_id_high, span.getParents()[i].getHigh()); parentRow.addLong(column_parent_child_span_id, span.getSpanId().getLow()); session.apply(parentInsert);
for (SpanId parent : span.getParents()) { jgen.writeString(parent.toString());
public static void appendJsonString(Span span, OutputStreamWriter writer) throws IOException { writer.append("{"); appendField(JSON_FIELD_TRACE_ID, span.getSpanId().getLow(), writer); appendField(JSON_FIELD_SPAN_ID, span.getSpanId().getHigh(), writer); appendField(JSON_FIELD_DESCRIPTION, span.getDescription(), writer); if (span.getParents().length != 0) { appendField(JSON_FIELD_PARENT_ID, span.getParents()[0].getLow(), writer); } appendField(JSON_FIELD_START, span.getStartTimeMillis(), writer); appendField(JSON_FIELD_STOP, span.getStopTimeMillis(), writer); if (!span.getTimelineAnnotations().isEmpty()) { writer.append("\""); writer.append(JSON_FIELD_TIMELINE); writer.append("\""); writer.append(":"); writer.append("["); for (TimelineAnnotation annotation : span.getTimelineAnnotations()) { writer.append("{"); appendField(JSON_FIELD_TIMELINE_TIME, annotation.getTime(), writer); appendField(JSON_FIELD_TIMELINE_MESSEGE, annotation.getMessage(), writer); writer.append("}"); } writer.append("]"); } writer.append("}"); }
assertEquals(expected.getSpanId(), got.getSpanId()); assertEquals(expected.getTracerId(), got.getTracerId()); assertTrue(Arrays.equals(expected.getParents(), got.getParents())); Map<String, String> expectedT = expected.getKVAnnotations(); Map<String, String> gotT = got.getKVAnnotations();
@Test public void TestSimpleScope() throws Exception { Tracer tracer = new Tracer.Builder(). name("TestSimpleScope"). tracerPool(new TracerPool("TestSimpleScope")). conf(HTraceConfiguration.fromKeyValuePairs( "sampler.classes", "AlwaysSampler")). build(); POJOSpanReceiver receiver = new POJOSpanReceiver(HTraceConfiguration.EMPTY); tracer.getTracerPool().addReceiver(receiver); TraceScope scope = tracer.newScope("Foo"); scope.close(); tracer.close(); Assert.assertEquals(1, receiver.getSpans().size()); Span span = receiver.getSpans().iterator().next(); Assert.assertEquals(0, span.getParents().length); }