Package io.opentelemetry.api.trace
Class SpanId
- java.lang.Object
-
- io.opentelemetry.api.trace.SpanId
-
@Immutable public final class SpanId extends Object
Helper methods for dealing with a span identifier. A valid span identifier is a 16 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 8-byte array, where valid means that at least one of the bytes is not `\0`.
- Long: a
longvalue, where valid means that the value is non-zero.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringfromBytes(byte[] spanIdBytes)Returns the lowercase hex (base16) representation of theSpanIdconverted from the given bytes representation, orgetInvalid()if input isnullor the given byte array is too short.static StringfromLong(long id)Returns the lowercase hex (base16) representation of theSpanIdconverted from the givenlongvalue representation.static StringgetInvalid()Returns the invalidSpanIdin lowercase hex (base16) representation.static intgetLength()Returns the length of the lowercase hex (base16) representation of theSpanId.static booleanisValid(CharSequence spanId)Returns whether the span identifier is valid.
-
-
-
Method Detail
-
getLength
public static int getLength()
Returns the length of the lowercase hex (base16) representation of theSpanId.- Returns:
- the length of the lowercase hex (base16) representation of the
SpanId.
-
getInvalid
public static String getInvalid()
Returns the invalidSpanIdin lowercase hex (base16) representation. All characters are "0".- Returns:
- the invalid
SpanIdlowercase in hex (base16) representation.
-
isValid
public static boolean isValid(CharSequence spanId)
Returns whether the span identifier is valid. A valid span identifier is a 16 character hex String, where at least one of the characters is not a '0'.- Returns:
trueif the span identifier is valid.
-
fromBytes
public static String fromBytes(byte[] spanIdBytes)
Returns the lowercase hex (base16) representation of theSpanIdconverted from the given bytes representation, orgetInvalid()if input isnullor the given byte array is too short.It converts the first 8 bytes of the given byte array.
- Parameters:
spanIdBytes- the bytes (8-byte array) representation of theSpanId.- Returns:
- the lowercase hex (base16) representation of the
SpanId.
-
fromLong
public static String fromLong(long id)
Returns the lowercase hex (base16) representation of theSpanIdconverted from the givenlongvalue representation.There is no restriction on the specified values, other than the already established validity rules applying to
SpanId. Specifying 0 for the long value will effectively returngetInvalid().This is equivalent to calling
fromBytes(byte[])with the specified value stored as big-endian.- Parameters:
id-longvalue representation of theSpanId.- Returns:
- the lowercase hex (base16) representation of the
SpanId.
-
-