public class Span extends Object implements SpanContext
Spans should form a directed acyclic graph structure. It should be possible to keep following the parents of a span until you arrive at a span with no parents.
Spans can be either annotated with tags or logs.
An Annotation is used to record existence of an event in time. Below you can find some of the core annotations used to define the start and stop of a request:
| Modifier and Type | Class and Description |
|---|---|
static class |
Span.SpanBuilder |
| Modifier and Type | Field and Description |
|---|---|
static String |
CLIENT_RECV
cr - Client Receive.
|
static String |
CLIENT_SEND
cs - Client Sent.
|
static String |
INSTANCEID
ID of the instance from which the span was originated.
|
static String |
PARENT_ID_NAME |
static String |
PROCESS_ID_NAME |
static String |
SAMPLED_NAME |
static String |
SERVER_RECV
sr - Server Receive.
|
static String |
SERVER_SEND
ss - Server Send.
|
static String |
SPAN_BAGGAGE_HEADER_PREFIX |
static String |
SPAN_ERROR_TAG_NAME |
static String |
SPAN_EXPORT_NAME |
static String |
SPAN_FLAGS |
static Set<String> |
SPAN_HEADERS |
static String |
SPAN_ID_NAME |
static String |
SPAN_LOCAL_COMPONENT_TAG_NAME |
static String |
SPAN_NAME_NAME |
static String |
SPAN_NOT_SAMPLED |
static String |
SPAN_PEER_SERVICE_TAG_NAME
|
static String |
SPAN_SAMPLED |
static String |
TRACE_ID_NAME |
| Constructor and Description |
|---|
Span(long begin,
long end,
String name,
long traceId,
List<Long> parents,
long spanId,
boolean remote,
boolean exportable,
String processId)
Deprecated.
please use
Span.SpanBuilder |
Span(long begin,
long end,
String name,
long traceId,
List<Long> parents,
long spanId,
boolean remote,
boolean exportable,
String processId,
Span savedSpan)
Deprecated.
please use
Span.SpanBuilder |
Span(Span current,
Span savedSpan)
Creates a new span that still tracks tags and logs of the current span.
|
| Modifier and Type | Method and Description |
|---|---|
Iterable<Map.Entry<String,String>> |
baggageItems() |
static Span.SpanBuilder |
builder() |
boolean |
equals(Object o) |
long |
getAccumulatedMicros()
Return the total amount of time elapsed since start was called, if running, or
difference between stop and start, in microseconds.
|
long |
getAccumulatedMillis()
Deprecated.
use
getAccumulatedMicros() as it is more precise. |
Map<String,String> |
getBaggage() |
String |
getBaggageItem(String key) |
long |
getBegin()
Get the start time, in milliseconds
|
long |
getEnd()
Get the stop time, in milliseconds
|
String |
getName()
A human-readable name assigned to this span instance.
|
List<Long> |
getParents()
Returns the parent IDs of the span.
|
String |
getProcessId()
Return a unique id for the process from which this span originated.
|
Span |
getSavedSpan()
Returns the saved span.
|
long |
getSpanId()
A pseudo-unique (random) number assigned to this span instance.
|
long |
getTraceId()
Unique 8-byte identifier for a trace, set on all spans within it.
|
long |
getTraceIdHigh()
When non-zero, the trace containing this span uses 128-bit trace identifiers.
|
int |
hashCode() |
boolean |
hasSavedSpan() |
static long |
hexToId(String hexString)
Parses a 1 to 32 character lower-hex string with no prefix into an unsigned long, tossing any
bits higher than 64.
|
static long |
hexToId(String lowerHex,
int index)
Parses a 16 character lower-hex string with no prefix into an unsigned long, starting at the
specified index.
|
static String |
idToHex(long id)
Represents given long id as 16-character lower-hex string
|
boolean |
isExportable()
Is the span eligible for export? If not then we may not need accumulate annotations
(for instance).
|
boolean |
isRemote()
Flag that tells us whether the span was started in another process.
|
boolean |
isRunning()
Has the span been started and not yet stopped?
|
void |
logEvent(long timestampMilliseconds,
String event)
Add a
event to a specific point (a timestamp in milliseconds) in the timeline
associated with this span. |
void |
logEvent(String event)
Add an
event to the timeline associated with this span. |
List<Log> |
logs()
Get any timestamped events (read only)
Will never be null.
|
Span |
setBaggageItem(String key,
String value)
Sets a baggage item in the Span (and its SpanContext) as a key/value pair.
|
void |
stop()
The block has completed, stop the clock
|
void |
tag(String key,
String value)
Add a tag or data annotation associated with this span.
|
Map<String,String> |
tags()
Get tag data associated with this span (read only)
Will never be null.
|
String |
toString() |
String |
traceIdString()
Returns the 16 or 32 character hex representation of the span's trace ID
|
public static final String SAMPLED_NAME
public static final String PROCESS_ID_NAME
public static final String PARENT_ID_NAME
public static final String TRACE_ID_NAME
public static final String SPAN_NAME_NAME
public static final String SPAN_ID_NAME
public static final String SPAN_EXPORT_NAME
public static final String SPAN_FLAGS
public static final String SPAN_BAGGAGE_HEADER_PREFIX
public static final String SPAN_SAMPLED
public static final String SPAN_NOT_SAMPLED
public static final String SPAN_LOCAL_COMPONENT_TAG_NAME
public static final String SPAN_ERROR_TAG_NAME
public static final String CLIENT_RECV
public static final String CLIENT_SEND
RestTemplate. This annotation depicts the
start of the span.public static final String SERVER_RECV
public static final String SERVER_SEND
public static final String SPAN_PEER_SERVICE_TAG_NAME
public static final String INSTANCEID
public Span(Span current, Span savedSpan)
@Deprecated public Span(long begin, long end, String name, long traceId, List<Long> parents, long spanId, boolean remote, boolean exportable, String processId)
Span.SpanBuilder@Deprecated public Span(long begin, long end, String name, long traceId, List<Long> parents, long spanId, boolean remote, boolean exportable, String processId, Span savedSpan)
Span.SpanBuilderpublic static Span.SpanBuilder builder()
public void stop()
@Deprecated public long getAccumulatedMillis()
getAccumulatedMicros() as it is more precise.public long getAccumulatedMicros()
public boolean isRunning()
public void tag(String key, String value)
public void logEvent(long timestampMilliseconds,
String event)
event to a specific point (a timestamp in milliseconds) in the timeline
associated with this span.public Span setBaggageItem(String key, String value)
public String getBaggageItem(String key)
public final Iterable<Map.Entry<String,String>> baggageItems()
baggageItems in interface SpanContextsetBaggageItem(String, String),
getBaggageItem(String)public Map<String,String> tags()
public Span getSavedSpan()
Might be null
public boolean hasSavedSpan()
public String getName()
public long getSpanId()
The span id is immutable and cannot be changed. It is safe to access this from multiple threads.
public long getTraceIdHigh()
traceIdHigh corresponds to the high bits in big-endian format and
getTraceId() corresponds to the low bits.
Ex. to convert the two fields to a 128bit opaque id array, you'd use code like below.
ByteBuffer traceId128 = ByteBuffer.allocate(16);
traceId128.putLong(span.getTraceIdHigh());
traceId128.putLong(span.getTraceId());
traceBytes = traceId128.array();
traceIdString()public long getTraceId()
public String getProcessId()
Might be null
public List<Long> getParents()
The collection will be empty if there are no parents.
public boolean isRemote()
public long getBegin()
public long getEnd()
public boolean isExportable()
public String traceIdString()
public static String idToHex(long id)
traceIdString()public static long hexToId(String hexString)
public static long hexToId(String lowerHex, int index)
Copyright © 2017 Pivotal Software, Inc.. All rights reserved.