RealKey(TraceContext context, ReferenceQueue<TraceContext> queue) { super(context, queue); hashCode = context.hashCode(); traceIdHigh = context.traceIdHigh(); traceId = context.traceId(); localRootId = context.localRootId(); spanId = context.spanId(); sampled = Boolean.TRUE.equals(context.sampled()); }
/** Resolves hash code collisions */ @Override public boolean equals(Object other) { RealKey that = (RealKey) other; TraceContext thatContext = that.get(); if (thatContext == null) return false; return (traceIdHigh == thatContext.traceIdHigh()) && (traceId == thatContext.traceId()) && (spanId == thatContext.spanId()) && shared == thatContext.shared(); } }
void set(TraceContext context) { set(context.traceIdHigh(), context.traceId(), context.spanId(), context.shared()); }
/** Trace contexts are equal only on trace ID and span ID. try to get the parent's clock */ @Nullable TickClock getClockFromParent(TraceContext context) { long parentId = context.parentIdAsLong(); // NOTE: we still look for lookup key even on root span, as a client span can be root, and a // server can share the same ID. Essentially, a shared span is similar to a child. PendingSpan parent = null; if (context.shared() || parentId != 0L) { long spanId = parentId != 0L ? parentId : context.spanId(); parent = delegate.get(InternalPropagation.instance.newTraceContext( 0, context.traceIdHigh(), context.traceId(), 0, 0, spanId, Collections.emptyList() )); } return parent != null ? parent.clock : null; }
static byte[] toBytes(TraceContext traceContext) { checkNotNull(traceContext, "traceContext"); byte[] bytes = new byte[FORMAT_LENGTH]; bytes[0] = VERSION; bytes[1] = TRACE_ID_FIELD_ID; writeLong(bytes, 2, traceContext.traceIdHigh()); writeLong(bytes, 10, traceContext.traceId()); bytes[18] = SPAN_ID_FIELD_ID; writeLong(bytes, 19, traceContext.spanId()); bytes[27] = TRACE_OPTION_FIELD_ID; if (traceContext.sampled() != null && traceContext.sampled()) { bytes[28] = 1; } return bytes; }
/** * Called by methods which can accept externally supplied parent trace contexts: Ex. {@link * #newChild(TraceContext)} and {@link #startScopedSpanWithParent(String, TraceContext)}. This * implies the {@link TraceContext#localRootId()} could be zero, if the context was manually * created. */ TraceContext nextContext(TraceContext parent) { return nextContext( InternalPropagation.instance.flags(parent), parent.traceIdHigh(), parent.traceId(), parent.localRootId(), parent.spanId(), parent.extra() ); }
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; }
context.traceIdHigh(), context.traceId(),
traceIdHigh = implicitParent.traceIdHigh(); traceId = implicitParent.traceId(); localRootId = implicitParent.localRootId();
RealKey(TraceContext context, ReferenceQueue<TraceContext> queue) { super(context, queue); hashCode = context.hashCode(); traceIdHigh = context.traceIdHigh(); traceId = context.traceId(); localRootId = context.localRootId(); spanId = context.spanId(); sampled = Boolean.TRUE.equals(context.sampled()); }
/** Resolves hash code collisions */ @Override public boolean equals(Object other) { RealKey that = (RealKey) other; TraceContext thatContext = that.get(); if (thatContext == null) return false; return (traceIdHigh == thatContext.traceIdHigh()) && (traceId == thatContext.traceId()) && (spanId == thatContext.spanId()) && shared == thatContext.shared(); } }
void set(TraceContext context) { set(context.traceIdHigh(), context.traceId(), context.spanId(), context.shared()); }
/** Trace contexts are equal only on trace ID and span ID. try to get the parent's clock */ @Nullable TickClock getClockFromParent(TraceContext context) { long parentId = context.parentIdAsLong(); // NOTE: we still look for lookup key even on root span, as a client span can be root, and a // server can share the same ID. Essentially, a shared span is similar to a child. PendingSpan parent = null; if (context.shared() || parentId != 0L) { long spanId = parentId != 0L ? parentId : context.spanId(); parent = delegate.get(InternalPropagation.instance.newTraceContext( 0, context.traceIdHigh(), context.traceId(), 0, 0, spanId, Collections.emptyList() )); } return parent != null ? parent.clock : null; }
static byte[] toBytes(TraceContext traceContext) { checkNotNull(traceContext, "traceContext"); byte[] bytes = new byte[FORMAT_LENGTH]; bytes[0] = VERSION; bytes[1] = TRACE_ID_FIELD_ID; writeLong(bytes, 2, traceContext.traceIdHigh()); writeLong(bytes, 10, traceContext.traceId()); bytes[18] = SPAN_ID_FIELD_ID; writeLong(bytes, 19, traceContext.spanId()); bytes[27] = TRACE_OPTION_FIELD_ID; if (traceContext.sampled() != null && traceContext.sampled()) { bytes[28] = 1; } return bytes; }
/** * Called by methods which can accept externally supplied parent trace contexts: Ex. {@link * #newChild(TraceContext)} and {@link #startScopedSpanWithParent(String, TraceContext)}. This * implies the {@link TraceContext#localRootId()} could be zero, if the context was manually * created. */ TraceContext nextContext(TraceContext parent) { return nextContext( InternalPropagation.instance.flags(parent), parent.traceIdHigh(), parent.traceId(), parent.localRootId(), parent.spanId(), parent.extra() ); }
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; }
/** 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()); }
static SpanId toSpanId(TraceContext context) { return SpanId.builder() .traceIdHigh(context.traceIdHigh()) .traceId(context.traceId()) .parentId(context.parentId()) .spanId(context.spanId()) .debug(context.debug()) .sampled(context.sampled()).build(); } }
context.traceIdHigh(), context.traceId(),
traceIdHigh = implicitParent.traceIdHigh(); traceId = implicitParent.traceId(); localRootId = implicitParent.localRootId();