Package io.opencensus.implcore.trace
Class RecordEventsSpanImpl
- java.lang.Object
-
- io.opencensus.trace.Span
-
- io.opencensus.implcore.trace.RecordEventsSpanImpl
-
- All Implemented Interfaces:
ConcurrentIntrusiveList.Element<RecordEventsSpanImpl>
@ThreadSafe public final class RecordEventsSpanImpl extends Span implements ConcurrentIntrusiveList.Element<RecordEventsSpanImpl>
Implementation for theSpanclass that records trace events.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classRecordEventsSpanImpl.AttributesWithCapacityprivate static classRecordEventsSpanImpl.EventWithNanoTime<T>static interfaceRecordEventsSpanImpl.StartEndHandlerInterface to handle the start and end operations for aSpanonly when theSpanhasSpan.Options.RECORD_EVENTSoption.private static classRecordEventsSpanImpl.TraceEvents<T>-
Nested classes/interfaces inherited from class io.opencensus.trace.Span
Span.Kind, Span.Options
-
-
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description privateRecordEventsSpanImpl(SpanContext context, java.lang.String name, Span.Kind kind, SpanId parentSpanId, java.lang.Boolean hasRemoteParent, TraceParams traceParams, RecordEventsSpanImpl.StartEndHandler startEndHandler, TimestampConverter timestampConverter, Clock clock)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAnnotation(Annotation annotation)Adds an annotation to theSpan.voidaddAnnotation(java.lang.String description, java.util.Map<java.lang.String,AttributeValue> attributes)Adds an annotation to theSpan.(package private) voidaddChild()voidaddLink(Link link)Adds aLinkto theSpan.voidaddMessageEvent(MessageEvent messageEvent)Adds a MessageEvent to theSpan.private static <T> SpanData.TimedEvents<T>createTimedEvents(RecordEventsSpanImpl.TraceEvents<RecordEventsSpanImpl.EventWithNanoTime<T>> events, TimestampConverter timestampConverter)voidend(EndSpanOptions options)Marks the end ofSpanexecution with the given options.longgetEndNanoTime()Returns the end nano time (seeSystem.nanoTime()).private RecordEventsSpanImpl.TraceEvents<RecordEventsSpanImpl.EventWithNanoTime<Annotation>>getInitializedAnnotations()private RecordEventsSpanImpl.AttributesWithCapacitygetInitializedAttributes()private RecordEventsSpanImpl.TraceEvents<Link>getInitializedLinks()private RecordEventsSpanImpl.TraceEvents<RecordEventsSpanImpl.EventWithNanoTime<MessageEvent>>getInitializedNetworkEvents()Span.KindgetKind()Returns the kind of thisSpan.longgetLatencyNs()Returns the latency of theSpanin nanos.java.lang.StringgetName()Returns the name of theSpan.RecordEventsSpanImplgetNext()Returns a reference to the next element in the list.RecordEventsSpanImplgetPrev()Returns a reference to the previous element in the list.booleangetSampleToLocalSpanStore()Returns if the name of thisSpanmust be register to theSampledSpanStore.StatusgetStatus()Returns the status of theSpan.private StatusgetStatusWithDefault()(package private) TimestampConvertergetTimestampConverter()Returns theTimestampConverterused by 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.voidsetNext(RecordEventsSpanImpl element)Sets the reference to the next element in the list.voidsetPrev(RecordEventsSpanImpl element)Sets the reference to the previous element in the list.voidsetStatus(Status status)Sets theStatusto theSpan.static RecordEventsSpanImplstartSpan(SpanContext context, java.lang.String name, Span.Kind kind, SpanId parentSpanId, java.lang.Boolean hasRemoteParent, TraceParams traceParams, RecordEventsSpanImpl.StartEndHandler startEndHandler, TimestampConverter timestampConverter, Clock clock)Creates and starts a span with the given configuration.SpanDatatoSpanData()Returns an immutable representation of all the data from thisSpan.-
Methods inherited from class io.opencensus.trace.Span
addAnnotation, addAttributes, addNetworkEvent, end, getContext, getOptions
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
RECORD_EVENTS_SPAN_OPTIONS
private static final java.util.EnumSet<Span.Options> RECORD_EVENTS_SPAN_OPTIONS
-
parentSpanId
@Nullable private final SpanId parentSpanId
-
hasRemoteParent
@Nullable private final java.lang.Boolean hasRemoteParent
-
traceParams
private final TraceParams traceParams
-
startEndHandler
private final RecordEventsSpanImpl.StartEndHandler startEndHandler
-
name
private final java.lang.String name
-
kind
@Nullable private final Span.Kind kind
-
clock
private final Clock clock
-
timestampConverter
private final TimestampConverter timestampConverter
-
startNanoTime
private final long startNanoTime
-
attributes
@Nullable private RecordEventsSpanImpl.AttributesWithCapacity attributes
-
annotations
@Nullable private RecordEventsSpanImpl.TraceEvents<RecordEventsSpanImpl.EventWithNanoTime<Annotation>> annotations
-
messageEvents
@Nullable private RecordEventsSpanImpl.TraceEvents<RecordEventsSpanImpl.EventWithNanoTime<MessageEvent>> messageEvents
-
links
@Nullable private RecordEventsSpanImpl.TraceEvents<Link> links
-
numberOfChildren
private int numberOfChildren
-
status
@Nullable private Status status
-
endNanoTime
private long endNanoTime
-
hasBeenEnded
private boolean hasBeenEnded
-
sampleToLocalSpanStore
private boolean sampleToLocalSpanStore
-
next
@Nullable private RecordEventsSpanImpl next
-
prev
@Nullable private RecordEventsSpanImpl prev
-
-
Constructor Detail
-
RecordEventsSpanImpl
private RecordEventsSpanImpl(SpanContext context, java.lang.String name, @Nullable Span.Kind kind, @Nullable SpanId parentSpanId, @Nullable java.lang.Boolean hasRemoteParent, TraceParams traceParams, RecordEventsSpanImpl.StartEndHandler startEndHandler, @Nullable TimestampConverter timestampConverter, Clock clock)
-
-
Method Detail
-
startSpan
public static RecordEventsSpanImpl startSpan(SpanContext context, java.lang.String name, @Nullable Span.Kind kind, @Nullable SpanId parentSpanId, @Nullable java.lang.Boolean hasRemoteParent, TraceParams traceParams, RecordEventsSpanImpl.StartEndHandler startEndHandler, @Nullable TimestampConverter timestampConverter, Clock clock)
Creates and starts a span with the given configuration.- Parameters:
context- supplies the trace_id and span_id for the newly started span.name- the displayed name for the new span.parentSpanId- the span_id of the parent span, or null if the new span is a root span.hasRemoteParent-trueif the parentContext is remote.nullif this is a root span.traceParams- trace parameters like sampler and probability.startEndHandler- handler called when the span starts and ends.timestampConverter- null if the span is a root span or the parent is not sampled. If the parent is sampled, we should use the same converter to ensure ordering between tracing events.clock- the clock used to get the time.- Returns:
- a new and started span.
-
getName
public java.lang.String getName()
Returns the name of theSpan.- Returns:
- the name of the
Span.
-
getStatus
public Status getStatus()
Returns the status of theSpan. If not set defaults toStatus.OK.- Returns:
- the status of the
Span.
-
getEndNanoTime
public long getEndNanoTime()
Returns the end nano time (seeSystem.nanoTime()). If the currentSpanis not ended then returnsClock.nowNanos().- Returns:
- the end nano time.
-
getLatencyNs
public long getLatencyNs()
Returns the latency of theSpanin nanos. If still active then returns now() - start time.- Returns:
- the latency of the
Spanin nanos.
-
getSampleToLocalSpanStore
public boolean getSampleToLocalSpanStore()
Returns if the name of thisSpanmust be register to theSampledSpanStore.- Returns:
- if the name of this
Spanmust be register to theSampledSpanStore.
-
getKind
@Nullable public Span.Kind getKind()
Returns the kind of thisSpan.- Returns:
- the kind of this
Span.
-
getTimestampConverter
@Nullable TimestampConverter getTimestampConverter()
Returns theTimestampConverterused by thisSpan.- Returns:
- the
TimestampConverterused by thisSpan.
-
toSpanData
public SpanData toSpanData()
Returns an immutable representation of all the data from thisSpan.- Returns:
- an immutable representation of all the data from this
Span. - Throws:
java.lang.IllegalStateException- if the Span doesn't have RECORD_EVENTS option.
-
putAttribute
public void putAttribute(java.lang.String key, AttributeValue value)Description copied from class:SpanSets an attribute to theSpan. If theSpanpreviously contained a mapping for the key, the old value is replaced by the specified value.- Overrides:
putAttributein classSpan- Parameters:
key- the key for this attribute.value- the value for this attribute.
-
putAttributes
public void putAttributes(java.util.Map<java.lang.String,AttributeValue> attributes)
Description copied from class:SpanSets a set of attributes to theSpan. The effect of this call is equivalent to that of callingSpan.putAttribute(String, AttributeValue)once for each element in the specified map.- Overrides:
putAttributesin classSpan- Parameters:
attributes- the attributes that will be added and associated with theSpan.
-
addAnnotation
public void addAnnotation(java.lang.String description, java.util.Map<java.lang.String,AttributeValue> attributes)Description copied from class:SpanAdds an annotation to theSpan.- Specified by:
addAnnotationin classSpan- Parameters:
description- the description of the annotation time event.attributes- the attributes that will be added; these are associated with this annotation, not theSpanas forSpan.putAttributes(Map).
-
addAnnotation
public void addAnnotation(Annotation annotation)
Description copied from class:SpanAdds an annotation to theSpan.- Specified by:
addAnnotationin classSpan- Parameters:
annotation- the annotations to add.
-
addMessageEvent
public void addMessageEvent(MessageEvent messageEvent)
Description copied from class:SpanAdds 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.- Overrides:
addMessageEventin classSpan- Parameters:
messageEvent- the message to add.
-
addLink
public void addLink(Link link)
Description copied from class:SpanAdds aLinkto theSpan.Used (for example) in batching operations, where a single batch handler processes multiple requests from different traces.
-
setStatus
public void setStatus(Status status)
Description copied from class:SpanSets 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.
-
end
public void end(EndSpanOptions options)
Description copied from class:SpanMarks 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.
-
addChild
void addChild()
-
getInitializedAttributes
private RecordEventsSpanImpl.AttributesWithCapacity getInitializedAttributes()
-
getInitializedAnnotations
private RecordEventsSpanImpl.TraceEvents<RecordEventsSpanImpl.EventWithNanoTime<Annotation>> getInitializedAnnotations()
-
getInitializedNetworkEvents
private RecordEventsSpanImpl.TraceEvents<RecordEventsSpanImpl.EventWithNanoTime<MessageEvent>> getInitializedNetworkEvents()
-
getInitializedLinks
private RecordEventsSpanImpl.TraceEvents<Link> getInitializedLinks()
-
getStatusWithDefault
private Status getStatusWithDefault()
-
createTimedEvents
private static <T> SpanData.TimedEvents<T> createTimedEvents(RecordEventsSpanImpl.TraceEvents<RecordEventsSpanImpl.EventWithNanoTime<T>> events, TimestampConverter timestampConverter)
-
getNext
@Nullable public RecordEventsSpanImpl getNext()
Description copied from interface:ConcurrentIntrusiveList.ElementReturns a reference to the next element in the list.- Specified by:
getNextin interfaceConcurrentIntrusiveList.Element<RecordEventsSpanImpl>- Returns:
- a reference to the next element in the list.
-
setNext
public void setNext(@Nullable RecordEventsSpanImpl element)Description copied from interface:ConcurrentIntrusiveList.ElementSets the reference to the next element in the list.- Specified by:
setNextin interfaceConcurrentIntrusiveList.Element<RecordEventsSpanImpl>- Parameters:
element- the reference to the next element in the list.
-
getPrev
@Nullable public RecordEventsSpanImpl getPrev()
Description copied from interface:ConcurrentIntrusiveList.ElementReturns a reference to the previous element in the list.- Specified by:
getPrevin interfaceConcurrentIntrusiveList.Element<RecordEventsSpanImpl>- Returns:
- a reference to the previous element in the list.
-
setPrev
public void setPrev(@Nullable RecordEventsSpanImpl element)Description copied from interface:ConcurrentIntrusiveList.ElementSets the reference to the previous element in the list.- Specified by:
setPrevin interfaceConcurrentIntrusiveList.Element<RecordEventsSpanImpl>- Parameters:
element- the reference to the previous element in the list.
-
-