SofaTracerSpanContext implements SpanContext { public String nextChildContextId() { return this.spanId + RPC_ID_SEPARATOR + childContextIndex.incrementAndGet(); } SofaTracerSpanContext();  SofaTracerSpanContext(String traceId, String spanId);  SofaTracerSpanContext(String traceId, String spanId, String parentId);  SofaTracerSpanContext(String traceId, String spanId, String parentId, boolean isSampled); SofaTracerSpanContext cloneInstance(); SofaTracerSpanContext addBizBaggage(Map<String, String> bizBaggage); SofaTracerSpanContext addSysBaggage(Map<String, String> sysBaggage); @Override Iterable<Map.Entry<String, String>> baggageItems(); String getBizSerializedBaggage(); String getSysSerializedBaggage(); void deserializeBizBaggage(String bizBaggageAttrs); void deserializeSysBaggage(String sysBaggageAttrs); String serializeSpanContext(); static SofaTracerSpanContext deserializeFromString(String deserializeValue); static SofaTracerSpanContext rootStart(); static SofaTracerSpanContext rootStart(boolean isSampled); void setTraceId(String traceId); void setSpanId(String spanId); SofaTracerSpanContext setBizBaggageItem(String key, String value); String getBizBaggageItem(String key); SofaTracerSpanContext setSysBaggageItem(String key, String value); String getSysBaggageItem(String key); String getTraceId(); String getSpanId(); String getParentId(); Map<String, String> getBizBaggage(); Map<String, String> getSysBaggage(); boolean isSampled(); void setSampled(boolean sampled); AtomicInteger getChildContextIndex(); String nextChildContextId(); String lastChildContextId(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static final String RPC_ID_SEPARATOR; }
@Test public void testNextChildContextId() throws Exception { SofaTracerSpanContext sofaTracerSpanContext = SofaTracerSpanContext.rootStart(); String childSpanId = sofaTracerSpanContext.nextChildContextId(); String childSpanId1 = sofaTracerSpanContext.nextChildContextId(); String childSpanId2 = sofaTracerSpanContext.nextChildContextId(); String childSpanId3 = sofaTracerSpanContext.nextChildContextId(); assertEquals(SofaTracer.ROOT_SPAN_ID, sofaTracerSpanContext.getSpanId()); assertEquals(2, childSpanId.split("\\.").length); assertEquals(2, childSpanId1.split("\\.").length); assertEquals(2, childSpanId2.split("\\.").length); assertEquals(2, childSpanId3.split("\\.").length); String[] childs = childSpanId.split("\\."); String[] childs1 = childSpanId1.split("\\."); String[] childs2 = childSpanId2.split("\\."); String[] childs3 = childSpanId3.split("\\."); assertTrue(SofaTracer.ROOT_SPAN_ID.equals(childs[0])); assertTrue(SofaTracer.ROOT_SPAN_ID.equals(childs1[0])); assertTrue(SofaTracer.ROOT_SPAN_ID.equals(childs2[0])); assertTrue(SofaTracer.ROOT_SPAN_ID.equals(childs3[0])); assertTrue("Children : " + childs[1] + "," + childs1[1] + "," + childs2[1] + "," + childs3[1], sofaTracerSpanContext.lastChildContextId().equals("0.4")); }