/** * Writes all B3 defined fields in the trace context to a hyphen delimited string. This is * appropriate for receivers who understand "b3" single header format. * * <p>The {@link TraceContext#parentIdAsLong() parent ID} is serialized in case the receiver is * an RPC server. When downstream is known to be a messaging consumer, or a server that never * reuses a client's span ID, prefer {@link #writeB3SingleFormatWithoutParentId(TraceContext)}. */ public static String writeB3SingleFormat(TraceContext context) { char[] buffer = getCharBuffer(); int length = writeB3SingleFormat(context, context.parentIdAsLong(), buffer); return new String(buffer, 0, length); }
/** * Like {@link #writeB3SingleFormatAsBytes(TraceContext)}, but for carriers with byte array or * byte buffer values. For example, {@link ByteBuffer#wrap(byte[])} can wrap the result. */ public static byte[] writeB3SingleFormatAsBytes(TraceContext context) { char[] buffer = getCharBuffer(); int length = writeB3SingleFormat(context, context.parentIdAsLong(), buffer); return asciiToNewByteArray(buffer, length); }
/** 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; }
context.traceId(), context.parentIdAsLong(), context.spanId(), context.extra()
/** * Writes all B3 defined fields in the trace context to a hyphen delimited string. This is * appropriate for receivers who understand "b3" single header format. * * <p>The {@link TraceContext#parentIdAsLong() parent ID} is serialized in case the receiver is * an RPC server. When downstream is known to be a messaging consumer, or a server that never * reuses a client's span ID, prefer {@link #writeB3SingleFormatWithoutParentId(TraceContext)}. */ public static String writeB3SingleFormat(TraceContext context) { char[] buffer = getCharBuffer(); int length = writeB3SingleFormat(context, context.parentIdAsLong(), buffer); return new String(buffer, 0, length); }
/** * Like {@link #writeB3SingleFormatAsBytes(TraceContext)}, but for carriers with byte array or * byte buffer values. For example, {@link ByteBuffer#wrap(byte[])} can wrap the result. */ public static byte[] writeB3SingleFormatAsBytes(TraceContext context) { char[] buffer = getCharBuffer(); int length = writeB3SingleFormat(context, context.parentIdAsLong(), buffer); return asciiToNewByteArray(buffer, length); }
/** 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; }
context.traceId(), context.parentIdAsLong(), context.spanId(), context.extra()