Package io.opentelemetry.api.trace
Class TraceId
- java.lang.Object
-
- io.opentelemetry.api.trace.TraceId
-
@Immutable public final class TraceId extends Object
Helper methods for dealing with a trace identifier. A valid trace identifier is a 16-byte array with at least one non-zero byte. In base-16 representation, a 32 character hex String, where at least one of the characters is not a '0'.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]bytesFromHex(String src, int srcOffset)Returns aTraceIdbuilt from a lowercase base16 representation.static StringbytesToHex(byte[] traceId)Returns the lowercase base16 encoding of thisTraceId.static voidcopyHexInto(byte[] traceId, char[] dest, int destOffset)Copies the lowercase base16 representations of theTraceIdinto thedestbeginning at thedestOffsetoffset.static StringfromLongs(long idHi, long idLo)Constructs aTraceIdwhose representation is specified by two long values representing the lower and higher parts.static intgetHexLength()Returns the length of the base16 (hex) representation of theTraceId.static StringgetInvalid()Returns the invalidTraceId.static intgetSize()Returns the size in bytes of theTraceId.static longgetTraceIdRandomPart(CharSequence traceId)Returns the rightmost 8 bytes of the trace-id as a long value.static booleanisValid(CharSequence traceId)Returns whether theTraceIdis valid.static longtraceIdHighBytesAsLong(CharSequence traceId)Convert the "high bytes" of the given hex traceId into a long representation.static longtraceIdLowBytesAsLong(CharSequence traceId)Convert the "low bytes" of the given hex traceId into a long representation.
-
-
-
Method Detail
-
getSize
public static int getSize()
Returns the size in bytes of theTraceId.- Returns:
- the size in bytes of the
TraceId.
-
getHexLength
public static int getHexLength()
Returns the length of the base16 (hex) representation of theTraceId.
-
getInvalid
public static String getInvalid()
Returns the invalidTraceId. All bytes are '\0'.- Returns:
- the invalid
TraceId.
-
fromLongs
public static String fromLongs(long idHi, long idLo)
Constructs aTraceIdwhose representation is specified by two long values representing the lower and higher parts.There is no restriction on the specified values, other than the already established validity rules applying to
TraceId. Specifying 0 for both values will effectively make the newTraceIdinvalid.This is equivalent to calling
bytesToHex(byte[])with the specified values stored as big-endian.- Parameters:
idHi- the higher part of theTraceId.idLo- the lower part of theTraceId.
-
bytesFromHex
public static byte[] bytesFromHex(String src, int srcOffset)
Returns aTraceIdbuilt from a lowercase base16 representation.- Parameters:
src- the lowercase base16 representation.srcOffset- the offset in the buffer where the representation of theTraceIdbegins.- Returns:
- a
TraceIdbuilt from a lowercase base16 representation. - Throws:
NullPointerException- ifsrcis null.IllegalArgumentException- if not enough characters in thesrcfrom thesrcOffset.
-
copyHexInto
public static void copyHexInto(byte[] traceId, char[] dest, int destOffset)Copies the lowercase base16 representations of theTraceIdinto thedestbeginning at thedestOffsetoffset.- Parameters:
dest- the destination buffer.destOffset- the starting offset in the destination buffer.- Throws:
IndexOutOfBoundsException- ifdestOffset + 2 * TraceId.getSize()is greater thandest.length.
-
isValid
public static boolean isValid(CharSequence traceId)
Returns whether theTraceIdis valid. A valid trace identifier is a 16-byte array with at least one non-zero byte.- Returns:
trueif theTraceIdis valid.
-
bytesToHex
public static String bytesToHex(byte[] traceId)
Returns the lowercase base16 encoding of thisTraceId.- Returns:
- the lowercase base16 encoding of this
TraceId.
-
getTraceIdRandomPart
public static long getTraceIdRandomPart(CharSequence traceId)
Returns the rightmost 8 bytes of the trace-id as a long value. This is used in ProbabilitySampler.This method is marked as internal and subject to change.
- Returns:
- the rightmost 8 bytes of the trace-id as a long value.
-
traceIdHighBytesAsLong
public static long traceIdHighBytesAsLong(CharSequence traceId)
Convert the "high bytes" of the given hex traceId into a long representation.
-
traceIdLowBytesAsLong
public static long traceIdLowBytesAsLong(CharSequence traceId)
Convert the "low bytes" of the given hex traceId into a long representation.
-
-