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 aTraceId
built from a lowercase base16 representation.static String
bytesToHex(byte[] traceId)
Returns the lowercase base16 encoding of thisTraceId
.static void
copyHexInto(byte[] traceId, char[] dest, int destOffset)
Copies the lowercase base16 representations of theTraceId
into thedest
beginning at thedestOffset
offset.static String
fromLongs(long idHi, long idLo)
Constructs aTraceId
whose representation is specified by two long values representing the lower and higher parts.static int
getHexLength()
Returns the length of the base16 (hex) representation of theTraceId
.static String
getInvalid()
Returns the invalidTraceId
.static int
getSize()
Returns the size in bytes of theTraceId
.static long
getTraceIdRandomPart(CharSequence traceId)
Returns the rightmost 8 bytes of the trace-id as a long value.static boolean
isValid(CharSequence traceId)
Returns whether theTraceId
is valid.static long
traceIdHighBytesAsLong(CharSequence traceId)
Convert the "high bytes" of the given hex traceId into a long representation.static long
traceIdLowBytesAsLong(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 aTraceId
whose 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 newTraceId
invalid.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 aTraceId
built from a lowercase base16 representation.- Parameters:
src
- the lowercase base16 representation.srcOffset
- the offset in the buffer where the representation of theTraceId
begins.- Returns:
- a
TraceId
built from a lowercase base16 representation. - Throws:
NullPointerException
- ifsrc
is null.IllegalArgumentException
- if not enough characters in thesrc
from thesrcOffset
.
-
copyHexInto
public static void copyHexInto(byte[] traceId, char[] dest, int destOffset)
Copies the lowercase base16 representations of theTraceId
into thedest
beginning at thedestOffset
offset.- 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 theTraceId
is valid. A valid trace identifier is a 16-byte array with at least one non-zero byte.- Returns:
true
if theTraceId
is 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.
-
-