Package io.opentelemetry.api.trace
Class TraceId
java.lang.Object
io.opentelemetry.api.trace.TraceId
Helper methods for dealing with a trace identifier. A valid trace identifier is a 32 character
lowercase hex (base16) String, where at least one of the characters is not a "0".
There are two more other representation that this class helps with:
- Bytes: a 16-byte array, where valid means that at least one of the bytes is not `\0`.
- Long: two
longvalues, where valid means that at least one of values is non-zero. To avoid allocating new objects this representation uses two parts, "high part" representing the left most part of theTraceIdand "low part" representing the right most part of theTraceId. This is equivalent with the values being stored as big-endian.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringfromBytes(byte[] traceIdBytes) Returns the lowercase hex (base16) representation of theTraceIdconverted from the given bytes representation, orgetInvalid()if input isnullor the given byte array is too short.static StringfromLongs(long traceIdLongHighPart, long traceIdLongLowPart) Returns the bytes (16-byte array) representation of theTraceIdconverted from the given twolongvalues representing the lower and higher parts.static StringReturns the invalidTraceIdin lowercase hex (base16) representation.static intReturns the length of the lowercase hex (base16) representation of theTraceId.static booleanisValid(CharSequence traceId) Returns whether theTraceIdis valid.
-
Method Details
-
getLength
public static int getLength()Returns the length of the lowercase hex (base16) representation of theTraceId.- Returns:
- the length of the lowercase hex (base16) representation of the
TraceId.
-
getInvalid
Returns the invalidTraceIdin lowercase hex (base16) representation. All characters are "0".- Returns:
- the invalid
TraceIdin lowercase hex (base16) representation.
-
isValid
Returns whether theTraceIdis valid. A valid trace identifier is a 32 character hex String, where at least one of the characters is not a '0'.- Returns:
trueif theTraceIdis valid.
-
fromBytes
Returns the lowercase hex (base16) representation of theTraceIdconverted from the given bytes representation, orgetInvalid()if input isnullor the given byte array is too short.It converts the first 26 bytes of the given byte array.
- Parameters:
traceIdBytes- the bytes (16-byte array) representation of theTraceId.- Returns:
- the lowercase hex (base16) representation of the
TraceId.
-
fromLongs
Returns the bytes (16-byte array) representation of theTraceIdconverted from the given twolongvalues 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 returngetInvalid().This is equivalent to calling
fromBytes(byte[])with the specified values stored as big-endian.- Parameters:
traceIdLongHighPart- the higher part of the long values representation of theTraceId.traceIdLongLowPart- the lower part of the long values representation of theTraceId.- Returns:
- the lowercase hex (base16) representation of the
TraceId.
-