traceId的生成
public String getTransactionId() {
return TransactionIdUtils.formatString(agentId, agentStartTime, transactionSequence);
}
public static final String TRANSACTION_ID_DELIMITER = "^";
public static String formatString(String agentId, long agentStartTime, long transactionSequence) {
if (agentId == null) {
throw new NullPointerException("agentId must not be null");
}
StringBuilder sb = new StringBuilder(64);
sb.append(agentId);
sb.append(TRANSACTION_ID_DELIMITER);
sb.append(agentStartTime);
sb.append(TRANSACTION_ID_DELIMITER);
sb.append(transactionSequence);
return sb.toString();
}
spanId的生成
public class SpanId {
public static final long NULL = -1;
// private static final Random seed = new Random();
public static long newSpanId() {
final Random random = getRandom();
return createSpanId(random);
}
// Changed to ThreadLocalRandom because unique value per thread will be enough.
// If you need to change Random implementation, modify this method.
private static Random getRandom() {
return ThreadLocalRandomUtils.current();
}
private static long createSpanId(Random seed) {
long id = seed.nextLong();
while (id == NULL) {
id = seed.nextLong();
}
return id;
}
public static long nextSpanID(long spanId, long parentSpanId) {
final Random seed = getRandom();
long newId = createSpanId(seed);
while (newId == spanId || newId == parentSpanId) {
newId = createSpanId(seed);
}
return newId;
}
}
docs
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。