Class Span
- java.lang.Object
-
- io.opencensus.trace.Span
-
- Direct Known Subclasses:
BlankSpan,NoRecordEventsSpanImpl,RecordEventsSpanImpl
public abstract class Span extends java.lang.ObjectAn abstract class that represents a span. It has an associatedSpanContextand a set ofSpan.Options.Spans are created by the
SpanBuilder.startSpan()method.Spanmust be ended by callingend()orend(EndSpanOptions)- Since:
- 0.5
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSpan.KindType of span.static classSpan.OptionsSpanoptions.
-
Field Summary
Fields Modifier and Type Field Description private SpanContextcontextprivate static java.util.Set<Span.Options>DEFAULT_OPTIONSprivate static java.util.Map<java.lang.String,AttributeValue>EMPTY_ATTRIBUTESprivate java.util.Set<Span.Options>options
-
Constructor Summary
Constructors Modifier Constructor Description protectedSpan(SpanContext context, java.util.EnumSet<Span.Options> options)Creates a newSpan.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract voidaddAnnotation(Annotation annotation)Adds an annotation to theSpan.voidaddAnnotation(java.lang.String description)Adds an annotation to theSpan.abstract voidaddAnnotation(java.lang.String description, java.util.Map<java.lang.String,AttributeValue> attributes)Adds an annotation to theSpan.voidaddAttributes(java.util.Map<java.lang.String,AttributeValue> attributes)Deprecated.abstract voidaddLink(Link link)Adds aLinkto theSpan.voidaddMessageEvent(MessageEvent messageEvent)Adds a MessageEvent to theSpan.voidaddNetworkEvent(NetworkEvent networkEvent)Deprecated.voidend()Marks the end ofSpanexecution with the default options.abstract voidend(EndSpanOptions options)Marks the end ofSpanexecution with the given options.SpanContextgetContext()Returns theSpanContextassociated with thisSpan.java.util.Set<Span.Options>getOptions()Returns the options associated with thisSpan.voidputAttribute(java.lang.String key, AttributeValue value)Sets an attribute to theSpan.voidputAttributes(java.util.Map<java.lang.String,AttributeValue> attributes)Sets a set of attributes to theSpan.voidsetStatus(Status status)Sets theStatusto theSpan.
-
-
-
Field Detail
-
EMPTY_ATTRIBUTES
private static final java.util.Map<java.lang.String,AttributeValue> EMPTY_ATTRIBUTES
-
context
private final SpanContext context
-
options
private final java.util.Set<Span.Options> options
-
DEFAULT_OPTIONS
private static final java.util.Set<Span.Options> DEFAULT_OPTIONS
-
-
Constructor Detail
-
Span
protected Span(SpanContext context, @Nullable java.util.EnumSet<Span.Options> options)
Creates a newSpan.- Parameters:
context- the context associated with thisSpan.options- the options associated with thisSpan. Ifnullthen default options will be set.- Throws:
java.lang.NullPointerException- if context isnull.java.lang.IllegalArgumentException- if theSpanContextis sampled but no RECORD_EVENTS options.- Since:
- 0.5
-
-
Method Detail
-
putAttribute
public void putAttribute(java.lang.String key, AttributeValue value)Sets an attribute to theSpan. If theSpanpreviously contained a mapping for the key, the old value is replaced by the specified value.- Parameters:
key- the key for this attribute.value- the value for this attribute.- Since:
- 0.6
-
putAttributes
public void putAttributes(java.util.Map<java.lang.String,AttributeValue> attributes)
Sets a set of attributes to theSpan. The effect of this call is equivalent to that of callingputAttribute(String, AttributeValue)once for each element in the specified map.- Parameters:
attributes- the attributes that will be added and associated with theSpan.- Since:
- 0.6
-
addAttributes
@Deprecated public void addAttributes(java.util.Map<java.lang.String,AttributeValue> attributes)
Deprecated.Sets a set of attributes to theSpan. The effect of this call is equivalent to that of callingputAttribute(String, AttributeValue)once for each element in the specified map.- Parameters:
attributes- the attributes that will be added and associated with theSpan.- Since:
- 0.5
-
addAnnotation
public final void addAnnotation(java.lang.String description)
Adds an annotation to theSpan.- Parameters:
description- the description of the annotation time event.- Since:
- 0.5
-
addAnnotation
public abstract void addAnnotation(java.lang.String description, java.util.Map<java.lang.String,AttributeValue> attributes)Adds an annotation to theSpan.- Parameters:
description- the description of the annotation time event.attributes- the attributes that will be added; these are associated with this annotation, not theSpanas forputAttributes(Map).- Since:
- 0.5
-
addAnnotation
public abstract void addAnnotation(Annotation annotation)
Adds an annotation to theSpan.- Parameters:
annotation- the annotations to add.- Since:
- 0.5
-
addNetworkEvent
@Deprecated public void addNetworkEvent(NetworkEvent networkEvent)
Deprecated.Adds a NetworkEvent to theSpan.This function is only intended to be used by RPC systems (either client or server), not by higher level applications.
- Parameters:
networkEvent- the network event to add.- Since:
- 0.5
-
addMessageEvent
public void addMessageEvent(MessageEvent messageEvent)
Adds a MessageEvent to theSpan.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.- Parameters:
messageEvent- the message to add.- Since:
- 0.12
-
addLink
public abstract void addLink(Link link)
Adds aLinkto theSpan.Used (for example) in batching operations, where a single batch handler processes multiple requests from different traces.
- Parameters:
link- the link to add.- Since:
- 0.5
-
setStatus
public void setStatus(Status status)
Sets theStatusto theSpan.If used, this will override the default
Spanstatus. Default isStatus.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.- Parameters:
status- theStatusto set.- Since:
- 0.9
-
end
public abstract void end(EndSpanOptions options)
Marks the end ofSpanexecution with the given options.Only the timing of the first end call for a given
Spanwill be recorded, and implementations are free to ignore all further calls.- Parameters:
options- the options to be used for the end of theSpan.- Since:
- 0.5
-
end
public final void end()
Marks the end ofSpanexecution with the default options.Only the timing of the first end call for a given
Spanwill be recorded, and implementations are free to ignore all further calls.- Since:
- 0.5
-
getContext
public final SpanContext getContext()
Returns theSpanContextassociated with thisSpan.- Returns:
- the
SpanContextassociated with thisSpan. - Since:
- 0.5
-
getOptions
public final java.util.Set<Span.Options> getOptions()
Returns the options associated with thisSpan.- Returns:
- the options associated with this
Span. - Since:
- 0.5
-
-