Top Description Fields Constructors Methods
io.opentelemetry.api.trace

public final Class TraceId

extends Object
Class Inheritance
Annotations
@Immutable
Imports
io.opentelemetry.api.internal.ApiUsageLogger, .OtelEncodingUtils, .TemporaryBuffers, javax.annotation.concurrent.Immutable

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:

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private static final String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

the lowercase hex (base16) representation of the TraceId.
fromBytes
(byte[]
the bytes (16-byte array) representation of the TraceId.
traceIdBytes
)

Returns the lowercase hex (base16) representation of the TraceId converted from the given bytes representation, or getInvalid() if input is null or the given byte array is too short.

public static String

Returns:

the lowercase hex (base16) representation of the TraceId.
fromLongs
(long
the higher part of the long values representation of the TraceId.
traceIdLongHighPart
,
long
the lower part of the long values representation of the TraceId.
traceIdLongLowPart
)

Returns the bytes (16-byte array) representation of the TraceId converted from the given two long values representing the lower and higher parts.

public static String

Returns:

the invalid TraceId in lowercase hex (base16) representation.
getInvalid
()

Returns the invalid TraceId in lowercase hex (base16) representation.

public static int

Returns:

the length of the lowercase hex (base16) representation of the TraceId.
getLength
()

Returns the length of the lowercase hex (base16) representation of the TraceId.

public static boolean

Returns:

true if the TraceId is valid.
isValid
(CharSequence traceId)

Returns whether the TraceId is valid.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BYTES_LENGTHback to summary
private static final int BYTES_LENGTH
HEX_LENGTHback to summary
private static final int HEX_LENGTH
INVALIDback to summary
private static final String INVALID

Constructor Detail

TraceIdback to summary
private TraceId()

Method Detail

fromBytesback to summary
public static String fromBytes(byte[] traceIdBytes)

Returns the lowercase hex (base16) representation of the TraceId converted from the given bytes representation, or getInvalid() if input is null or the given byte array is too short.

It converts the first 26 bytes of the given byte array.

Parameters
traceIdBytes:byte[]

the bytes (16-byte array) representation of the TraceId.

Returns:String

the lowercase hex (base16) representation of the TraceId.

fromLongsback to summary
public static String fromLongs(long traceIdLongHighPart, long traceIdLongLowPart)

Returns the bytes (16-byte array) representation of the TraceId converted from the given 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 return getInvalid().

This is equivalent to calling fromBytes(byte[]) with the specified values stored as big-endian.

Parameters
traceIdLongHighPart:long

the higher part of the long values representation of the TraceId.

traceIdLongLowPart:long

the lower part of the long values representation of the TraceId.

Returns:String

the lowercase hex (base16) representation of the TraceId.

getInvalidback to summary
public static String getInvalid()

Returns the invalid TraceId in lowercase hex (base16) representation. All characters are "0".

Returns:String

the invalid TraceId in lowercase hex (base16) representation.

getLengthback to summary
public static int getLength()

Returns the length of the lowercase hex (base16) representation of the TraceId.

Returns:int

the length of the lowercase hex (base16) representation of the TraceId.

isValidback to summary
public static boolean isValid(CharSequence traceId)

Returns whether the TraceId is valid. A valid trace identifier is a 32 character hex String, where at least one of the characters is not a '0'.

Returns:boolean

true if the TraceId is valid.