/** Returns {@code $traceId/$spanId} */ @Override public String toString() { boolean traceHi = traceIdHigh != 0; char[] result = new char[((traceHi ? 3 : 2) * 16) + 1]; // 2 ids and the delimiter int pos = 0; if (traceHi) { writeHexLong(result, pos, traceIdHigh); pos += 16; } writeHexLong(result, pos, traceId); pos += 16; result[pos++] = '/'; writeHexLong(result, pos, spanId); return new String(result); }
/** Returns {@code $traceId} */ @Override public String toString() { boolean traceHi = traceIdHigh != 0; char[] result = new char[traceHi ? 32 : 16]; int pos = 0; if (traceHi) { writeHexLong(result, pos, traceIdHigh); pos += 16; } writeHexLong(result, pos, traceId); return new String(result); }
/** Inspired by {@code okio.Buffer.writeLong} */ public static String toLowerHex(long v) { char[] data = new char[16]; writeHexLong(data, 0, v); return new String(data); }
/** Returns the hex representation of the span's trace ID */ public String traceIdString() { String r = traceIdString; if (r == null) { if (traceIdHigh != 0) { char[] result = new char[32]; writeHexLong(result, 0, traceIdHigh); writeHexLong(result, 16, traceId); r = new String(result); } else { r = toLowerHex(traceId); } traceIdString = r; } return r; }
static int writeB3SingleFormat(TraceContext context, long parentId, char[] result) { int pos = 0; long traceIdHigh = context.traceIdHigh(); if (traceIdHigh != 0L) { writeHexLong(result, pos, traceIdHigh); pos += 16; } writeHexLong(result, pos, context.traceId()); pos += 16; result[pos++] = '-'; writeHexLong(result, pos, context.spanId()); pos += 16; Boolean sampled = context.sampled(); if (sampled != null) { result[pos++] = '-'; result[pos++] = context.debug() ? 'd' : sampled ? '1' : '0'; } if (parentId != 0L) { result[pos++] = '-'; writeHexLong(result, pos, parentId); pos += 16; } return pos; }
/** Returns {@code $traceId/$spanId} */ @Override public String toString() { boolean traceHi = traceIdHigh != 0; char[] result = new char[((traceHi ? 3 : 2) * 16) + 1]; // 2 ids and the delimiter int pos = 0; if (traceHi) { writeHexLong(result, pos, traceIdHigh); pos += 16; } writeHexLong(result, pos, traceId); pos += 16; result[pos++] = '/'; writeHexLong(result, pos, spanId); return new String(result); }
/** Returns {@code $traceId} */ @Override public String toString() { boolean traceHi = traceIdHigh != 0; char[] result = new char[traceHi ? 32 : 16]; int pos = 0; if (traceHi) { writeHexLong(result, pos, traceIdHigh); pos += 16; } writeHexLong(result, pos, traceId); return new String(result); }
/** Inspired by {@code okio.Buffer.writeLong} */ public static String toLowerHex(long v) { char[] data = new char[16]; writeHexLong(data, 0, v); return new String(data); }
/** Returns the hex representation of the span's trace ID */ public String traceIdString() { String r = traceIdString; if (r == null) { if (traceIdHigh != 0) { char[] result = new char[32]; writeHexLong(result, 0, traceIdHigh); writeHexLong(result, 16, traceId); r = new String(result); } else { r = toLowerHex(traceId); } traceIdString = r; } return r; }
static int writeB3SingleFormat(TraceContext context, long parentId, char[] result) { int pos = 0; long traceIdHigh = context.traceIdHigh(); if (traceIdHigh != 0L) { writeHexLong(result, pos, traceIdHigh); pos += 16; } writeHexLong(result, pos, context.traceId()); pos += 16; result[pos++] = '-'; writeHexLong(result, pos, context.spanId()); pos += 16; Boolean sampled = context.sampled(); if (sampled != null) { result[pos++] = '-'; result[pos++] = context.debug() ? 'd' : sampled ? '1' : '0'; } if (parentId != 0L) { result[pos++] = '-'; writeHexLong(result, pos, parentId); pos += 16; } return pos; }
writeRoot(traceContext, result, 5); System.arraycopy(PARENT, 0, result, 40, 8); writeHexLong(result, 48, traceContext.spanId()); System.arraycopy(SAMPLED, 0, result, 64, 9); Boolean sampled = traceContext.sampled();
/** Writes 35 characters representing the input trace ID to the buffer at the given offset */ static void writeRoot(TraceContext context, char[] result, int offset) { result[offset] = '1'; // version result[offset + 1] = '-'; // delimiter long high = context.traceIdHigh(); writeHexByte(result, offset + 2, (byte) ((high >>> 56L) & 0xff)); writeHexByte(result, offset + 4, (byte) ((high >>> 48L) & 0xff)); writeHexByte(result, offset + 6, (byte) ((high >>> 40L) & 0xff)); writeHexByte(result, offset + 8, (byte) ((high >>> 32L) & 0xff)); result[offset + 10] = '-'; writeHexByte(result, offset + 11, (byte) ((high >>> 24L) & 0xff)); writeHexByte(result, offset + 13, (byte) ((high >>> 16L) & 0xff)); writeHexByte(result, offset + 15, (byte) ((high >>> 8L) & 0xff)); writeHexByte(result, offset + 17, (byte) (high & 0xff)); writeHexLong(result, offset + 19, context.traceId()); }