SpanId parentSpanId = new SpanId( header.getTraceInfo().getTraceId(), header.getTraceInfo().getParentId());
public void addTraceParent(SpanId id) { if (!id.isValid()) { return; } if (traceParentsUsed == traceParents.length) { int newLength = (traceParents.length == 0) ? 8 : traceParents.length * 2; traceParents = Arrays.copyOf(traceParents, newLength); } traceParents[traceParentsUsed] = id; traceParentsUsed++; }
public SpanId newChildId() { return new SpanId(high, nonZeroRand64()); } }
@Override public void requestShortCircuitShm(String clientName) throws IOException { ShortCircuitShmRequestProto.Builder builder = ShortCircuitShmRequestProto.newBuilder(). setClientName(clientName); SpanId spanId = Tracer.getCurrentSpanId(); if (spanId.isValid()) { builder.setTraceInfo(DataTransferTraceInfoProto.newBuilder(). setTraceId(spanId.getHigh()). setParentId(spanId.getLow())); } ShortCircuitShmRequestProto proto = builder.build(); send(out, Op.REQUEST_SHORT_CIRCUIT_SHM, proto); }
@Test(timeout=60000) public void testRootSpansHaveNonZeroSpanId() throws Exception { Tracer tracer = new Tracer.Builder(). name("testRootSpansHaveNonZeroSpanId"). tracerPool(new TracerPool("testRootSpansHaveNonZeroSpanId")). conf(HTraceConfiguration.fromKeyValuePairs( "sampler.classes", "AlwaysSampler")).build(); TraceScope scope = tracer. newScope("myRootSpan", new SpanId(100L, 200L)); Assert.assertNotNull(scope); Assert.assertEquals("myRootSpan", scope.getSpan().getDescription()); Assert.assertTrue(scope.getSpan().getSpanId().isValid()); Assert.assertEquals(100L, scope.getSpan().getSpanId().getHigh()); Assert.assertNotEquals(0L, scope.getSpan().getSpanId().getLow()); scope.close(); } }
TraceScope activeScope = tracer.newScope("CurrentActiveScope"); HashMap<Integer,SpanId> spanIdHashMap = new HashMap<>(); SpanId parentID = new SpanId(100L, 200L); spanIdHashMap.put(activeScope.getSpanId().hashCode(),activeScope.getSpanId()); spanIdHashMap.put(parentID.hashCode(),parentID); TraceScope childScope = tracer. newScope("ChildScope", parentID); 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();
ThreadContext context = threadContext.get(); if (parentScope != null) { if (parentId.isValid() && (!parentId.equals(parentScope.getSpan().getSpanId()))) { return newScopeImpl(context, description, parentScope, parentId); } else { return newScopeImpl(context, description, parentScope); } else if (parentId.isValid()) { return newScopeImpl(context, description, parentId);
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); }
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()); } } }
TraceScope parent = tracer.newScope("HBaseSpanReceiver.main.parent"); Thread.sleep(10); long traceid = parent.getSpan().getSpanId().getHigh(); TraceScope child1 = tracer.newScope("HBaseSpanReceiver.main.child.1"); Thread.sleep(10);
private void testRoundTrip(SpanId id) throws Exception { String str = id.toString(); SpanId id2 = SpanId.fromString(str); Assert.assertEquals(id, id2); }
@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); }
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); }
builder.spanId(SpanId.fromString(sNode.asText())); iter.hasNext(); ) { JsonNode parentIdNode = iter.next(); parents.add(SpanId.fromString(parentIdNode.asText()));
if (!val.equals(prevVal)) { traceParents[j] = val; j++;
@Override public void releaseShortCircuitFds(SlotId slotId) throws IOException { ReleaseShortCircuitAccessRequestProto.Builder builder = ReleaseShortCircuitAccessRequestProto.newBuilder(). setSlotId(PBHelperClient.convert(slotId)); SpanId spanId = Tracer.getCurrentSpanId(); if (spanId.isValid()) { builder.setTraceInfo(DataTransferTraceInfoProto.newBuilder(). setTraceId(spanId.getHigh()). setParentId(spanId.getLow())); } ReleaseShortCircuitAccessRequestProto proto = builder.build(); send(out, Op.RELEASE_SHORT_CIRCUIT_FDS, proto); }
public SpanId newChildId() { return new SpanId(high, nonZeroRand64()); } }