RowResult result = results.next(); long traceId = result.getLong(KuduClientConstants.DEFAULT_KUDU_COLUMN_SPAN_TRACE_ID); MilliSpan.Builder builder = new MilliSpan.Builder() .spanId(new SpanId(result.getLong(KuduClientConstants.DEFAULT_KUDU_COLUMN_SPAN_SPAN_ID), result.getLong(KuduClientConstants.DEFAULT_KUDU_COLUMN_SPAN_TRACE_ID))) .description(result.getString(KuduClientConstants.DEFAULT_KUDU_COLUMN_SPAN_DESCRIPTION)) .begin(result.getLong(KuduClientConstants.DEFAULT_KUDU_COLUMN_SPAN_START_TIME)) .end(result.getLong(KuduClientConstants.DEFAULT_KUDU_COLUMN_SPAN_STOP_TIME)); if (!(result.getLong(KuduClientConstants.DEFAULT_KUDU_COLUMN_SPAN_PARENT_ID_HIGH) == 0 && result.getLong(KuduClientConstants.DEFAULT_KUDU_COLUMN_SPAN_PARENT_ID_LOW) == 0)) { parents[0] = new SpanId(result.getLong(KuduClientConstants.DEFAULT_KUDU_COLUMN_SPAN_PARENT_ID_HIGH), result.getLong(KuduClientConstants.DEFAULT_KUDU_COLUMN_SPAN_PARENT_ID_LOW)); builder.parents(parents); builder.timeline(timelineList); dbSpan = builder.build(); spans.add(dbSpan);
throws IOException, JsonProcessingException { JsonNode root = jp.getCodec().readTree(jp); Builder builder = new Builder(); JsonNode bNode = root.get("b"); if (bNode != null) { builder.begin(bNode.asLong()); builder.end(eNode.asLong()); builder.description(dNode.asText()); builder.spanId(SpanId.fromString(sNode.asText())); builder.tracerId(rNode.asText()); builder.parents(parents); JsonNode traceInfoNode = root.get("n"); if (traceInfoNode != null) { traceInfo.put(field, traceInfoNode.get(field).asText()); builder.traceInfo(traceInfo); ann.get("m").asText())); builder.timeline(timeline); return builder.build();
RowResult result = results.next(); long traceId = result.getLong(KuduClientConstants.DEFAULT_KUDU_COLUMN_SPAN_TRACE_ID); MilliSpan.Builder builder = new MilliSpan.Builder() .spanId(new SpanId(result.getLong(KuduClientConstants.DEFAULT_KUDU_COLUMN_SPAN_SPAN_ID), result.getLong(KuduClientConstants.DEFAULT_KUDU_COLUMN_SPAN_TRACE_ID))) .description(result.getString(KuduClientConstants.DEFAULT_KUDU_COLUMN_SPAN_DESCRIPTION)) .begin(result.getLong(KuduClientConstants.DEFAULT_KUDU_COLUMN_SPAN_START_TIME)) .end(result.getLong(KuduClientConstants.DEFAULT_KUDU_COLUMN_SPAN_STOP_TIME)); List<String> timelineColumns = new ArrayList<>(); timelineColumns.add(KuduClientConstants.DEFAULT_KUDU_COLUMN_TIMELINE_TIME); builder.timeline(timelineList); dbSpan = builder.build(); spans.add(dbSpan);
throws IOException, JsonProcessingException { JsonNode root = jp.getCodec().readTree(jp); Builder builder = new Builder(); JsonNode bNode = root.get("b"); if (bNode != null) { builder.begin(bNode.asLong()); builder.end(eNode.asLong()); builder.description(dNode.asText()); builder.spanId(SpanId.fromString(sNode.asText())); builder.tracerId(rNode.asText()); builder.parents(parents); JsonNode traceInfoNode = root.get("n"); if (traceInfoNode != null) { traceInfo.put(field, traceInfoNode.get(field).asText()); builder.traceInfo(traceInfo); ann.get("m").asText())); builder.timeline(timeline); return builder.build();
throws IOException, JsonProcessingException { JsonNode root = jp.getCodec().readTree(jp); Builder builder = new Builder(); JsonNode bNode = root.get("b"); if (bNode != null) { builder.begin(bNode.asLong()); builder.end(eNode.asLong()); builder.description(dNode.asText()); builder.spanId(SpanId.fromString(sNode.asText())); builder.tracerId(rNode.asText()); builder.parents(parents); JsonNode traceInfoNode = root.get("n"); if (traceInfoNode != null) { traceInfo.put(field, traceInfoNode.get(field).asText()); builder.traceInfo(traceInfo); ann.get("m").asText())); builder.timeline(timeline); return builder.build();
Span ms = new MilliSpan.Builder(). description(tracerId).parents(new SpanId[] { }). spanId(new SpanId(2L, 2L)). tracerId(tracerId). begin(System.currentTimeMillis()). build();
public static Span randomSpan(Random rand) { MilliSpan.Builder builder = new MilliSpan.Builder(); builder.spanId( new SpanId(nonZeroRandomLong(rand), nonZeroRandomLong(rand))); builder.begin(positiveRandomLong(rand)); builder.end(positiveRandomLong(rand)); builder.description(randomString(rand)); builder.tracerId(randomString(rand)); int numParents = rand.nextInt(4); SpanId[] parents = new SpanId[numParents]; new SpanId(nonZeroRandomLong(rand), nonZeroRandomLong(rand)); builder.parents(parents); int numTraceInfos = rand.nextInt(4); Map<String, String> traceInfo = new HashMap<String, String>(numTraceInfos); traceInfo.put(randomString(rand), randomString(rand)); builder.traceInfo(traceInfo); int numTimelineAnnotations = rand.nextInt(4); List<TimelineAnnotation> timeline = randomString(rand))); builder.timeline(timeline); return builder.build();
@Test public void testHTraceDefaultPort() throws IOException { MilliSpan ms = new MilliSpan.Builder().description("test"). parents(new SpanId[] { new SpanId(2L, 2L) }). spanId(new SpanId(2L, 3L)). tracerId("hmaster"). begin(System.currentTimeMillis()). build(); com.twitter.zipkin.gen.Span zs = new HTraceToZipkinConverter(12345, (short) -1).convert(ms); for (com.twitter.zipkin.gen.Annotation annotation:zs.getAnnotations()) { assertEquals((short)60000, annotation.getHost().getPort()); } // make sure it's all lower cased ms = new MilliSpan.Builder().description("test"). parents(new SpanId[] {new SpanId(2, 2)}). spanId(new SpanId(2, 3)). tracerId("HregIonServer"). begin(System.currentTimeMillis()). build(); zs = new HTraceToZipkinConverter(12345, (short) -1).convert(ms); for (com.twitter.zipkin.gen.Annotation annotation:zs.getAnnotations()) { assertEquals((short)60020, annotation.getHost().getPort()); } }
@Test(timeout=120000) public void testSimpleTraces() throws IOException, InterruptedException { Tracer tracer = newTracer(); Span rootSpan = new MilliSpan.Builder(). description("root"). spanId(new SpanId(100, 100)). tracerId("test"). begin(System.currentTimeMillis()). build(); TraceScope rootScope = tracer.newScope("root"); TraceScope innerOne = tracer.newScope("innerOne"); TraceScope innerTwo = tracer.newScope("innerTwo"); innerTwo.close(); Assert.assertTrue(flumeServer.nextEventBodyAsString().contains("innerTwo")); innerOne.close(); Assert.assertTrue(flumeServer.nextEventBodyAsString().contains("innerOne")); rootSpan.addKVAnnotation("foo", "bar"); rootSpan.addTimelineAnnotation("timeline"); rootScope.close(); Assert.assertTrue(flumeServer.nextEventBodyAsString().contains("root")); tracer.close(); }
@Test public void testHTraceToZipkin() throws IOException { Span rootSpan = new MilliSpan.Builder(). description(ROOT_SPAN_DESC). parents(new SpanId[] { } ). spanId(new SpanId(100, 100)). tracerId("test"). begin(System.currentTimeMillis()). build(); Span innerOne = rootSpan.child("Some good work"); Span innerTwo = innerOne.child("Some more good work"); innerTwo.stop(); innerOne.stop(); rootSpan.addKVAnnotation("foo", "bar"); rootSpan.addTimelineAnnotation("timeline"); rootSpan.stop(); for (Span s : new Span[] {rootSpan, innerOne, innerTwo}) { com.twitter.zipkin.gen.Span zs = new HTraceToZipkinConverter(12345, (short) 12).convert(s); assertSpansAreEquivalent(s, zs); } }
@Test public void testJsonSerializationWithOptionalFields() throws Exception { MilliSpan.Builder builder = new MilliSpan.Builder(). description("foospan"). begin(300). end(400). parents(new SpanId[] { }). tracerId("b2408.halxg.com:8080"). spanId(new SpanId(111111111L, 111111111L)); Map<String, String> traceInfo = new HashMap<String, String>(); traceInfo.put("abc", "123"); traceInfo.put("def", "456"); builder.traceInfo(traceInfo); List<TimelineAnnotation> timeline = new LinkedList<TimelineAnnotation>(); timeline.add(new TimelineAnnotation(310L, "something happened")); timeline.add(new TimelineAnnotation(380L, "something else happened")); timeline.add(new TimelineAnnotation(390L, "more things")); builder.timeline(timeline); MilliSpan span = builder.build(); String json = span.toJson(); MilliSpan dspan = MilliSpan.fromJson(json); compareSpans(span, dspan); }
public List<Span> find(String tracerId) { List<Span> spans = new ArrayList<Span>(); Span span = new MilliSpan.Builder(). spanId(SpanId.INVALID). tracerId(tracerId). build(); while (true) { span = treeSet.higher(span); if (span == null) { break; } if (span.getTracerId().equals(tracerId)) { break; } spans.add(span); } return spans; }
@Test public void testSimpleTraces() throws IOException, InterruptedException { FakeZipkinTransport transport = new FakeZipkinTransport(); Tracer tracer = newTracer(transport); Span rootSpan = new MilliSpan.Builder(). description("root"). spanId(new SpanId(100, 100)). tracerId("test"). begin(System.currentTimeMillis()). build(); TraceScope rootScope = tracer.newScope("root"); TraceScope innerOne = tracer.newScope("innerOne"); TraceScope innerTwo = tracer.newScope("innerTwo"); innerTwo.close(); Assert.assertTrue(transport.nextMessageAsSpan().getName().contains("innerTwo")); innerOne.close(); Assert.assertTrue(transport.nextMessageAsSpan().getName().contains("innerOne")); rootSpan.addKVAnnotation("foo", "bar"); rootSpan.addTimelineAnnotation("timeline"); rootScope.close(); Assert.assertTrue(transport.nextMessageAsSpan().getName().contains("root")); tracer.close(); }
@Test public void testJsonSerializationWithRandomLongValue() throws Exception { SpanId parentId = SpanId.fromRandom(); MilliSpan span = new MilliSpan.Builder(). description("foospan"). begin(ThreadLocalRandom.current().nextLong()). end(ThreadLocalRandom.current().nextLong()). parents(new SpanId[] { parentId }). tracerId("b2404.halxg.com:8080"). spanId(parentId.newChildId()). build(); String json = span.toJson(); MilliSpan dspan = MilliSpan.fromJson(json); compareSpans(span, dspan); }
@Test public void testJsonSerializationWithNegativeLongValue() throws Exception { MilliSpan span = new MilliSpan.Builder(). description("foospan"). begin(-1L). end(-1L). parents(new SpanId[] { new SpanId(-1L, -1L) }). tracerId("b2404.halxg.com:8080"). spanId(new SpanId(-1L, -2L)). build(); String json = span.toJson(); MilliSpan dspan = MilliSpan.fromJson(json); compareSpans(span, dspan); }
@Test public void testJsonSerializationWithFieldsNotSet() throws Exception { MilliSpan span = new MilliSpan.Builder().build(); String json = span.toJson(); MilliSpan dspan = MilliSpan.fromJson(json); compareSpans(span, dspan); } }
private TraceScope newScopeImpl(ThreadContext context, String description, SpanId parentId) { Span span = new MilliSpan.Builder(). tracerId(tracerId). begin(System.currentTimeMillis()). description(description). parents(new SpanId[] { parentId }). spanId(parentId.newChildId()). build(); return context.pushNewScope(this, span, null); }
@Test public void testJsonSerialization() throws Exception { MilliSpan span = new MilliSpan.Builder(). description("foospan"). begin(123L). end(456L). parents(new SpanId[] { new SpanId(7L, 7L) }). tracerId("b2404.halxg.com:8080"). spanId(new SpanId(7L, 8L)). build(); String json = span.toJson(); MilliSpan dspan = MilliSpan.fromJson(json); compareSpans(span, dspan); }
private TraceScope newScopeImpl(ThreadContext context, String description) { Span span = new MilliSpan.Builder(). tracerId(tracerId). begin(System.currentTimeMillis()). description(description). parents(EMPTY_PARENT_ARRAY). spanId(SpanId.fromRandom()). build(); return context.pushNewScope(this, span, null); }
private TraceScope newScopeImpl(ThreadContext context, String description, TraceScope parentScope) { SpanId parentId = parentScope.getSpan().getSpanId(); Span span = new MilliSpan.Builder(). tracerId(tracerId). begin(System.currentTimeMillis()). description(description). parents(new SpanId[] { parentId }). spanId(parentId.newChildId()). build(); return context.pushNewScope(this, span, parentScope); }