public abstract class Span extends Object
SpanContext
and a set of
Span.Options
.
Spans are created by the SpanBuilder.startSpan()
method.
Span
must be ended by calling end()
or end(EndSpanOptions)
Modifier and Type | Class and Description |
---|---|
static class |
Span.Kind
Type of span.
|
static class |
Span.Options
Span options. |
Modifier | Constructor and Description |
---|---|
protected |
Span(SpanContext context,
EnumSet<Span.Options> options)
Creates a new
Span . |
Modifier and Type | Method and Description |
---|---|
abstract void |
addAnnotation(Annotation annotation)
Adds an annotation to the
Span . |
void |
addAnnotation(String description)
Adds an annotation to the
Span . |
abstract void |
addAnnotation(String description,
Map<String,AttributeValue> attributes)
Adds an annotation to the
Span . |
void |
addAttributes(Map<String,AttributeValue> attributes)
Deprecated.
|
abstract void |
addLink(Link link)
Adds a
Link to the Span . |
void |
addMessageEvent(MessageEvent messageEvent)
Adds a MessageEvent to the
Span . |
void |
addNetworkEvent(NetworkEvent networkEvent)
Deprecated.
|
void |
end()
Marks the end of
Span execution with the default options. |
abstract void |
end(EndSpanOptions options)
Marks the end of
Span execution with the given options. |
SpanContext |
getContext()
Returns the
SpanContext associated with this Span . |
Set<Span.Options> |
getOptions()
Returns the options associated with this
Span . |
void |
putAttribute(String key,
AttributeValue value)
Sets an attribute to the
Span . |
void |
putAttributes(Map<String,AttributeValue> attributes)
Sets a set of attributes to the
Span . |
void |
setStatus(Status status)
Sets the
Status to the Span . |
protected Span(SpanContext context, @Nullable EnumSet<Span.Options> options)
Span
.context
- the context associated with this Span
.options
- the options associated with this Span
. If null
then default
options will be set.NullPointerException
- if context is null
.IllegalArgumentException
- if the SpanContext
is sampled but no RECORD_EVENTS
options.public void putAttribute(String key, AttributeValue value)
Span
. If the Span
previously contained a mapping for
the key, the old value is replaced by the specified value.key
- the key for this attribute.value
- the value for this attribute.public void putAttributes(Map<String,AttributeValue> attributes)
Span
. The effect of this call is equivalent to that of
calling putAttribute(String, AttributeValue)
once for each element in the specified
map.attributes
- the attributes that will be added and associated with the Span
.@Deprecated public void addAttributes(Map<String,AttributeValue> attributes)
putAttributes(Map)
Span
. The effect of this call is equivalent to that of
calling putAttribute(String, AttributeValue)
once for each element in the specified
map.attributes
- the attributes that will be added and associated with the Span
.public final void addAnnotation(String description)
Span
.description
- the description of the annotation time event.public abstract void addAnnotation(String description, Map<String,AttributeValue> attributes)
Span
.description
- the description of the annotation time event.attributes
- the attributes that will be added; these are associated with this annotation,
not the Span
as for putAttributes(Map)
.public abstract void addAnnotation(Annotation annotation)
Span
.annotation
- the annotations to add.@Deprecated public void addNetworkEvent(NetworkEvent networkEvent)
addMessageEvent(io.opencensus.trace.MessageEvent)
.Span
.
This function is only intended to be used by RPC systems (either client or server), not by higher level applications.
networkEvent
- the network event to add.public void addMessageEvent(MessageEvent messageEvent)
Span
.
This function can be used by higher level applications to record messaging event.
This method should always be overridden by users whose API versions are larger or equal to
0.12
.
messageEvent
- the message to add.public abstract void addLink(Link link)
Link
to the Span
.
Used (for example) in batching operations, where a single batch handler processes multiple requests from different traces.
link
- the link to add.public void setStatus(Status status)
Status
to the Span
.
If used, this will override the default Span
status. Default is Status.OK
.
Only the value of the last call will be recorded, and implementations are free to ignore
previous calls. If the status is set via EndSpanOptions.Builder.setStatus(Status)
that
will always be the last call.
status
- the Status
to set.public abstract void end(EndSpanOptions options)
Span
execution with the given options.
Only the timing of the first end call for a given Span
will be recorded, and
implementations are free to ignore all further calls.
options
- the options to be used for the end of the Span
.public final void end()
Span
execution with the default options.
Only the timing of the first end call for a given Span
will be recorded, and
implementations are free to ignore all further calls.
public final SpanContext getContext()
SpanContext
associated with this Span
.SpanContext
associated with this Span
.public final Set<Span.Options> getOptions()
Span
.Span
.