public final class Span extends Object implements Comparable<Span>, Serializable
Spans are usually created by instrumentation in RPC clients or servers, but can also represent in-process activity. Annotations in spans are similar to log statements, and are sometimes created directly by application developers to indicate events of interest, such as a cache miss.
The root span is where parentId
is null; it usually has the longest duration
in the
trace.
Span identifiers are packed into longs, but should be treated opaquely. ID encoding is 16 or 32 character lower-hex, to avoid signed interpretation.
Modifier and Type | Class and Description |
---|---|
static class |
Span.Builder |
Modifier and Type | Field and Description |
---|---|
List<Annotation> |
annotations
Associates events that explain latency with a timestamp.
|
List<BinaryAnnotation> |
binaryAnnotations
Tags a span with context, usually to support query or aggregation.
|
Boolean |
debug
True is a request to store this span even if it overrides sampling policy.
|
Long |
duration
Measurement in microseconds of the critical path, if known.
|
long |
id
Unique 8-byte identifier of this span within a trace.
|
String |
name
Span name in lowercase, rpc method for example.
|
Long |
parentId
The parent's
id or null if this the root span in a trace. |
Long |
timestamp
Epoch microseconds of the start of this span, possibly absent if this an incomplete span.
|
long |
traceId
Unique 8-byte identifier for a trace, set on all spans within it.
|
long |
traceIdHigh
When non-zero, the trace containing this span uses 128-bit trace identifiers.
|
Modifier and Type | Method and Description |
---|---|
static Span.Builder |
builder() |
int |
compareTo(Span that)
|
boolean |
equals(Object o) |
int |
hashCode() |
String |
idString()
Returns
$traceId.$spanId<:$parentId or $spanId |
Set<String> |
serviceNames()
Returns the distinct
service names that logged to this span. |
Span.Builder |
toBuilder() |
String |
toString() |
String |
traceIdString()
Returns the hex representation of the span's trace ID
|
public final long traceIdHigh
traceIdHigh
corresponds to the high bits in big-endian format and traceId
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.traceIdHigh);
traceId128.putLong(span.traceId);
traceBytes = traceId128.array();
StorageComponent.Builder#strictTraceId(boolean)
public final long traceId
public final String name
Conventionally, when the span name isn't known, name = "unknown".
public final long id
A span is uniquely identified in storage by (traceId, #id
).
@Nullable public final Long parentId
id
or null if this the root span in a trace.@Nullable public final Long timestamp
This value should be set directly by instrumentation, using the most precise value
possible. For example, gettimeofday
or multiplying System.currentTimeMillis()
by
1000.
For compatibility with instrumentation that precede this field, collectors or span stores
can derive this via Annotation.timestamp. For example, Constants.SERVER_RECV
.timestamp
or Constants.CLIENT_SEND
.timestamp.
Timestamp is nullable for input only. Spans without a timestamp cannot be presented in a timeline: Span stores should not output spans missing a timestamp.
There are two known edge-cases where this could be absent: both cases exist when a collector receives a span in parts and a binary annotation precedes a timestamp. This is possible when..
@Nullable public final Long duration
This value should be set directly, as opposed to implicitly via annotation timestamps. Doing so encourages precision decoupled from problems of clocks, such as skew or NTP updates causing time to move backwards.
For compatibility with instrumentation that precede this field, collectors or span stores
can derive this by subtracting Annotation.timestamp
. For example, Constants.SERVER_SEND
.timestamp - Constants.SERVER_RECV
.timestamp.
If this field is persisted as unset, zipkin will continue to work, except duration query support will be implementation-specific. Similarly, setting this field non-atomically is implementation-specific.
This field is i64 vs i32 to support spans longer than 35 minutes.
public final List<Annotation> annotations
Unlike log statements, annotations are often codes: for example Constants.SERVER_RECV
. Annotations are sorted ascending by timestamp.
public final List<BinaryAnnotation> binaryAnnotations
example, a binary annotation key could be "http.path"
.
@Nullable public final Boolean debug
public Span.Builder toBuilder()
public static Span.Builder builder()
public int compareTo(Span that)
compareTo
in interface Comparable<Span>
public String traceIdString()
public String idString()
$traceId.$spanId<:$parentId or $spanId
public Set<String> serviceNames()
service names
that logged to this span.Copyright © 2015–2018 OpenZipkin. All rights reserved.