Package io.opencensus.trace
Class TraceId
java.lang.Object
io.opencensus.trace.TraceId
- All Implemented Interfaces:
Comparable<TraceId>
A class that represents a trace identifier. A valid trace identifier is a 16-byte array with at
least one non-zero byte.
- Since:
- 0.5
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private final long
private final long
static final TraceId
The invalidTraceId
.private static final long
static final int
The size in bytes of theTraceId
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
void
copyBytesTo
(byte[] dest, int destOffset) Copies the byte array representations of theTraceId
into thedest
beginning at thedestOffset
offset.void
copyLowerBase16To
(char[] dest, int destOffset) Copies the lowercase base16 representations of theTraceId
into thedest
beginning at thedestOffset
offset.boolean
static TraceId
fromBytes
(byte[] src) Returns aTraceId
built from a byte representation.static TraceId
fromBytes
(byte[] src, int srcOffset) Returns aTraceId
whose representation is copied from thesrc
beginning at thesrcOffset
offset.static TraceId
Returns aTraceId
built from a lowercase base16 representation.static TraceId
fromLowerBase16
(CharSequence src, int srcOffset) Returns aTraceId
built from a lowercase base16 representation.static TraceId
generateRandomId
(Random random) Generates a new randomTraceId
.byte[]
getBytes()
Returns the 16-bytes array representation of theTraceId
.long
Returns the lower 8 bytes of the trace-id as a long value, assuming little-endian order.int
hashCode()
boolean
isValid()
Returns whether theTraceId
is valid.Returns the lowercase base16 encoding of thisTraceId
.toString()
-
Field Details
-
SIZE
public static final int SIZEThe size in bytes of theTraceId
.- Since:
- 0.5
- See Also:
-
BASE16_SIZE
private static final int BASE16_SIZE- See Also:
-
INVALID_ID
private static final long INVALID_ID- See Also:
-
INVALID
The invalidTraceId
. All bytes are '\0'.- Since:
- 0.5
-
idHi
private final long idHi -
idLo
private final long idLo
-
-
Constructor Details
-
TraceId
private TraceId(long idHi, long idLo)
-
-
Method Details
-
fromBytes
Returns aTraceId
built from a byte representation.- Parameters:
src
- the representation of theTraceId
.- Returns:
- a
TraceId
whose representation is given by thesrc
parameter. - Throws:
NullPointerException
- ifsrc
is null.IllegalArgumentException
- ifsrc.length
is notSIZE
.- Since:
- 0.5
-
fromBytes
Returns aTraceId
whose representation is copied from thesrc
beginning at thesrcOffset
offset.- Parameters:
src
- the buffer where the representation of theTraceId
is copied.srcOffset
- the offset in the buffer where the representation of theTraceId
begins.- Returns:
- a
TraceId
whose representation is copied from the buffer. - Throws:
NullPointerException
- ifsrc
is null.IndexOutOfBoundsException
- ifsrcOffset+TraceId.SIZE
is greater thansrc.length
.- Since:
- 0.5
-
fromLowerBase16
Returns aTraceId
built from a lowercase base16 representation.- Parameters:
src
- the lowercase base16 representation.- Returns:
- a
TraceId
built from a lowercase base16 representation. - Throws:
NullPointerException
- ifsrc
is null.IllegalArgumentException
- ifsrc.length
is not2 * TraceId.SIZE
OR if thestr
has invalid characters.- Since:
- 0.11
-
fromLowerBase16
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
.- Since:
- 0.11
-
generateRandomId
Generates a new randomTraceId
.- Parameters:
random
- the random number generator.- Returns:
- a new valid
TraceId
. - Since:
- 0.5
-
getBytes
public byte[] getBytes()Returns the 16-bytes array representation of theTraceId
.- Returns:
- the 16-bytes array representation of the
TraceId
. - Since:
- 0.5
-
copyBytesTo
public void copyBytesTo(byte[] dest, int destOffset) Copies the byte array representations of theTraceId
into thedest
beginning at thedestOffset
offset.- Parameters:
dest
- the destination buffer.destOffset
- the starting offset in the destination buffer.- Throws:
NullPointerException
- ifdest
is null.IndexOutOfBoundsException
- ifdestOffset+TraceId.SIZE
is greater thandest.length
.- Since:
- 0.5
-
copyLowerBase16To
public void copyLowerBase16To(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.SIZE
is greater thandest.length
.- Since:
- 0.18
-
isValid
public boolean isValid()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.- Since:
- 0.5
-
toLowerBase16
Returns the lowercase base16 encoding of thisTraceId
.- Returns:
- the lowercase base16 encoding of this
TraceId
. - Since:
- 0.11
-
getLowerLong
Returns the lower 8 bytes of the trace-id as a long value, assuming little-endian order. This is used in ProbabilitySampler.This method is marked as internal and subject to change.
- Returns:
- the lower 8 bytes of the trace-id as a long value, assuming little-endian order.
-
equals
-
hashCode
public int hashCode() -
toString
-
compareTo
- Specified by:
compareTo
in interfaceComparable<TraceId>
-