Package io.opencensus.trace
Class TraceOptions
- java.lang.Object
-
- io.opencensus.trace.TraceOptions
-
@Immutable public final class TraceOptions extends java.lang.Object
A class that represents global trace options. These options are propagated to all childspans
. These determine features such as whether aSpan
should be traced. It is implemented as a bitmask.- Since:
- 0.5
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TraceOptions.Builder
Builder class forTraceOptions
.
-
Field Summary
Fields Modifier and Type Field Description private static int
BASE16_SIZE
static TraceOptions
DEFAULT
The defaultTraceOptions
.private static byte
DEFAULT_OPTIONS
private static byte
IS_SAMPLED
private byte
options
static int
SIZE
The size in bytes of theTraceOptions
.
-
Constructor Summary
Constructors Modifier Constructor Description private
TraceOptions(byte options)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static TraceOptions.Builder
builder()
Returns a newTraceOptions.Builder
with default options.static TraceOptions.Builder
builder(TraceOptions traceOptions)
Returns a newTraceOptions.Builder
with all given options set.void
copyBytesTo(byte[] dest, int destOffset)
Copies the byte representations of theTraceOptions
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
equals(java.lang.Object obj)
static TraceOptions
fromByte(byte src)
Returns aTraceOptions
whose representation issrc
.static TraceOptions
fromBytes(byte[] buffer)
Deprecated.usefromByte(byte)
.static TraceOptions
fromBytes(byte[] src, int srcOffset)
Deprecated.usefromByte(byte)
.static TraceOptions
fromLowerBase16(java.lang.CharSequence src, int srcOffset)
Returns aTraceOption
built from a lowercase base16 representation.byte
getByte()
Returns the one byte representation of theTraceOptions
.byte[]
getBytes()
Deprecated.usegetByte()
.(package private) byte
getOptions()
int
hashCode()
private boolean
hasOption(int mask)
boolean
isSampled()
Returns a boolean indicating whether thisSpan
is part of a sampled trace and data should be exported to a persistent store.java.lang.String
toLowerBase16()
Returns the lowercase base16 encoding of thisTraceOptions
.java.lang.String
toString()
-
-
-
Field Detail
-
DEFAULT_OPTIONS
private static final byte DEFAULT_OPTIONS
- See Also:
- Constant Field Values
-
IS_SAMPLED
private static final byte IS_SAMPLED
- See Also:
- Constant Field Values
-
SIZE
public static final int SIZE
The size in bytes of theTraceOptions
.- Since:
- 0.5
- See Also:
- Constant Field Values
-
BASE16_SIZE
private static final int BASE16_SIZE
- See Also:
- Constant Field Values
-
DEFAULT
public static final TraceOptions DEFAULT
The defaultTraceOptions
.- Since:
- 0.5
-
options
private final byte options
-
-
Method Detail
-
fromBytes
@Deprecated public static TraceOptions fromBytes(byte[] buffer)
Deprecated.usefromByte(byte)
.Returns aTraceOptions
built from a byte representation.Equivalent with:
TraceOptions.fromBytes(buffer, 0);
- Parameters:
buffer
- the representation of theTraceOptions
.- Returns:
- a
TraceOptions
whose representation is given by thebuffer
parameter. - Throws:
java.lang.NullPointerException
- ifbuffer
is null.java.lang.IllegalArgumentException
- ifbuffer.length
is notSIZE
.- Since:
- 0.5
-
fromBytes
@Deprecated public static TraceOptions fromBytes(byte[] src, int srcOffset)
Deprecated.usefromByte(byte)
.Returns aTraceOptions
whose representation is copied from thesrc
beginning at thesrcOffset
offset.- Parameters:
src
- the buffer where the representation of theTraceOptions
is copied.srcOffset
- the offset in the buffer where the representation of theTraceOptions
begins.- Returns:
- a
TraceOptions
whose representation is copied from the buffer. - Throws:
java.lang.NullPointerException
- ifsrc
is null.java.lang.IndexOutOfBoundsException
- ifsrcOffset+TraceOptions.SIZE
is greater thansrc.length
.- Since:
- 0.5
-
fromByte
public static TraceOptions fromByte(byte src)
Returns aTraceOptions
whose representation issrc
.- Parameters:
src
- the byte representation of theTraceOptions
.- Returns:
- a
TraceOptions
whose representation issrc
. - Since:
- 0.16
-
fromLowerBase16
public static TraceOptions fromLowerBase16(java.lang.CharSequence src, int srcOffset)
Returns aTraceOption
built from a lowercase base16 representation.- Parameters:
src
- the lowercase base16 representation.srcOffset
- the offset in the buffer where the representation of theTraceOptions
begins.- Returns:
- a
TraceOption
built from a lowercase base16 representation. - Throws:
java.lang.NullPointerException
- ifsrc
is null.java.lang.IllegalArgumentException
- ifsrc.length
is not2 * TraceOption.SIZE
OR if thestr
has invalid characters.- Since:
- 0.18
-
getByte
public byte getByte()
Returns the one byte representation of theTraceOptions
.- Returns:
- the one byte representation of the
TraceOptions
. - Since:
- 0.16
-
getBytes
@Deprecated public byte[] getBytes()
Deprecated.usegetByte()
.Returns the 1-byte array representation of theTraceOptions
.- Returns:
- the 1-byte array representation of the
TraceOptions
. - Since:
- 0.5
-
copyBytesTo
public void copyBytesTo(byte[] dest, int destOffset)
Copies the byte representations of theTraceOptions
into thedest
beginning at thedestOffset
offset.Equivalent with (but faster because it avoids any new allocations):
System.arraycopy(getBytes(), 0, dest, destOffset, TraceOptions.SIZE);
- Parameters:
dest
- the destination buffer.destOffset
- the starting offset in the destination buffer.- Throws:
java.lang.NullPointerException
- ifdest
is null.java.lang.IndexOutOfBoundsException
- ifdestOffset+TraceOptions.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:
java.lang.IndexOutOfBoundsException
- ifdestOffset + 2
is greater thandest.length
.- Since:
- 0.18
-
toLowerBase16
public java.lang.String toLowerBase16()
Returns the lowercase base16 encoding of thisTraceOptions
.- Returns:
- the lowercase base16 encoding of this
TraceOptions
. - Since:
- 0.18
-
builder
public static TraceOptions.Builder builder()
Returns a newTraceOptions.Builder
with default options.- Returns:
- a new
Builder
with default options. - Since:
- 0.5
-
builder
public static TraceOptions.Builder builder(TraceOptions traceOptions)
Returns a newTraceOptions.Builder
with all given options set.- Parameters:
traceOptions
- the given options set.- Returns:
- a new
Builder
with all given options set. - Since:
- 0.5
-
isSampled
public boolean isSampled()
Returns a boolean indicating whether thisSpan
is part of a sampled trace and data should be exported to a persistent store.- Returns:
- a boolean indicating whether the trace is sampled.
- Since:
- 0.5
-
equals
public boolean equals(@Nullable java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getOptions
byte getOptions()
-
hasOption
private boolean hasOption(int mask)
-
-