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 the
Span
class that records trace events.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
private static final class
static interface
Interface to handle the start and end operations for aSpan
only when theSpan
hasSpan.Options.RECORD_EVENTS
option.private static final class
Nested classes/interfaces inherited from class io.opencensus.trace.Span
Span.Kind, Span.Options
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Clock
private long
private boolean
private final Boolean
private final Span.Kind
private RecordEventsSpanImpl.TraceEvents
<Link> private static final Logger
private final String
private RecordEventsSpanImpl
private int
private final SpanId
private RecordEventsSpanImpl
private static final EnumSet
<Span.Options> private boolean
private final RecordEventsSpanImpl.StartEndHandler
private final long
private Status
private final TimestampConverter
private final TraceParams
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
RecordEventsSpanImpl
(SpanContext context, String name, Span.Kind kind, SpanId parentSpanId, Boolean hasRemoteParent, TraceParams traceParams, RecordEventsSpanImpl.StartEndHandler startEndHandler, TimestampConverter timestampConverter, Clock clock) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAnnotation
(Annotation annotation) Adds an annotation to theSpan
.void
addAnnotation
(String description, Map<String, AttributeValue> attributes) Adds an annotation to theSpan
.(package private) void
addChild()
void
Adds aLink
to theSpan
.void
addMessageEvent
(MessageEvent messageEvent) Adds a MessageEvent to theSpan
.private static <T> SpanData.TimedEvents
<T> createTimedEvents
(RecordEventsSpanImpl.TraceEvents<RecordEventsSpanImpl.EventWithNanoTime<T>> events, TimestampConverter timestampConverter) void
end
(EndSpanOptions options) Marks the end ofSpan
execution with the given options.long
Returns the end nano time (seeSystem.nanoTime()
).private RecordEventsSpanImpl.TraceEvents
<Link> getKind()
Returns the kind of thisSpan
.long
Returns the latency of theSpan
in nanos.getName()
Returns the name of theSpan
.getNext()
Returns a reference to the next element in the list.getPrev()
Returns a reference to the previous element in the list.boolean
Returns if the name of thisSpan
must be register to theSampledSpanStore
.Returns the status of theSpan
.private Status
(package private) TimestampConverter
Returns theTimestampConverter
used by thisSpan
.void
putAttribute
(String key, AttributeValue value) Sets an attribute to theSpan
.void
putAttributes
(Map<String, AttributeValue> attributes) Sets a set of attributes to theSpan
.void
setNext
(RecordEventsSpanImpl element) Sets the reference to the next element in the list.void
setPrev
(RecordEventsSpanImpl element) Sets the reference to the previous element in the list.void
Sets theStatus
to theSpan
.static RecordEventsSpanImpl
startSpan
(SpanContext context, String name, Span.Kind kind, SpanId parentSpanId, Boolean hasRemoteParent, TraceParams traceParams, RecordEventsSpanImpl.StartEndHandler startEndHandler, TimestampConverter timestampConverter, Clock clock) Creates and starts a span with the given configuration.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 Details
-
logger
-
RECORD_EVENTS_SPAN_OPTIONS
-
parentSpanId
-
hasRemoteParent
-
traceParams
-
startEndHandler
-
name
-
kind
-
clock
-
timestampConverter
-
startNanoTime
private final long startNanoTime -
attributes
-
annotations
@Nullable private RecordEventsSpanImpl.TraceEvents<RecordEventsSpanImpl.EventWithNanoTime<Annotation>> annotations -
messageEvents
@Nullable private RecordEventsSpanImpl.TraceEvents<RecordEventsSpanImpl.EventWithNanoTime<MessageEvent>> messageEvents -
links
-
numberOfChildren
private int numberOfChildren -
status
-
endNanoTime
private long endNanoTime -
hasBeenEnded
private boolean hasBeenEnded -
sampleToLocalSpanStore
private boolean sampleToLocalSpanStore -
next
-
prev
-
-
Constructor Details
-
RecordEventsSpanImpl
private RecordEventsSpanImpl(SpanContext context, String name, @Nullable Span.Kind kind, @Nullable SpanId parentSpanId, @Nullable Boolean hasRemoteParent, TraceParams traceParams, RecordEventsSpanImpl.StartEndHandler startEndHandler, @Nullable TimestampConverter timestampConverter, Clock clock)
-
-
Method Details
-
startSpan
public static RecordEventsSpanImpl startSpan(SpanContext context, String name, @Nullable Span.Kind kind, @Nullable SpanId parentSpanId, @Nullable 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
-true
if the parentContext is remote.null
if 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
Returns the name of theSpan
.- Returns:
- the name of the
Span
.
-
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 currentSpan
is not ended then returnsClock.nowNanos()
.- Returns:
- the end nano time.
-
getLatencyNs
public long getLatencyNs()Returns the latency of theSpan
in nanos. If still active then returns now() - start time.- Returns:
- the latency of the
Span
in nanos.
-
getSampleToLocalSpanStore
public boolean getSampleToLocalSpanStore()Returns if the name of thisSpan
must be register to theSampledSpanStore
.- Returns:
- if the name of this
Span
must be register to theSampledSpanStore
.
-
getKind
Returns the kind of thisSpan
.- Returns:
- the kind of this
Span
.
-
getTimestampConverter
Returns theTimestampConverter
used by thisSpan
.- Returns:
- the
TimestampConverter
used by thisSpan
.
-
toSpanData
Returns an immutable representation of all the data from thisSpan
.- Returns:
- an immutable representation of all the data from this
Span
. - Throws:
IllegalStateException
- if the Span doesn't have RECORD_EVENTS option.
-
putAttribute
Description copied from class:Span
Sets an attribute to theSpan
. If theSpan
previously contained a mapping for the key, the old value is replaced by the specified value.- Overrides:
putAttribute
in classSpan
- Parameters:
key
- the key for this attribute.value
- the value for this attribute.
-
putAttributes
Description copied from class:Span
Sets 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:
putAttributes
in classSpan
- Parameters:
attributes
- the attributes that will be added and associated with theSpan
.
-
addAnnotation
Description copied from class:Span
Adds an annotation to theSpan
.- Specified by:
addAnnotation
in classSpan
- Parameters:
description
- the description of the annotation time event.attributes
- the attributes that will be added; these are associated with this annotation, not theSpan
as forSpan.putAttributes(Map)
.
-
addAnnotation
Description copied from class:Span
Adds an annotation to theSpan
.- Specified by:
addAnnotation
in classSpan
- Parameters:
annotation
- the annotations to add.
-
addMessageEvent
Description copied from class:Span
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
.- Overrides:
addMessageEvent
in classSpan
- Parameters:
messageEvent
- the message to add.
-
addLink
Description copied from class:Span
Adds aLink
to theSpan
.Used (for example) in batching operations, where a single batch handler processes multiple requests from different traces.
-
setStatus
Description copied from class:Span
Sets theStatus
to theSpan
.If used, this will override the default
Span
status. 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
Description copied from class:Span
Marks the end ofSpan
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. -
addChild
void addChild() -
getInitializedAttributes
-
getInitializedAnnotations
private RecordEventsSpanImpl.TraceEvents<RecordEventsSpanImpl.EventWithNanoTime<Annotation>> getInitializedAnnotations() -
getInitializedNetworkEvents
private RecordEventsSpanImpl.TraceEvents<RecordEventsSpanImpl.EventWithNanoTime<MessageEvent>> getInitializedNetworkEvents() -
getInitializedLinks
-
getStatusWithDefault
-
createTimedEvents
private static <T> SpanData.TimedEvents<T> createTimedEvents(RecordEventsSpanImpl.TraceEvents<RecordEventsSpanImpl.EventWithNanoTime<T>> events, TimestampConverter timestampConverter) -
getNext
Description copied from interface:ConcurrentIntrusiveList.Element
Returns a reference to the next element in the list.- Specified by:
getNext
in interfaceConcurrentIntrusiveList.Element<RecordEventsSpanImpl>
- Returns:
- a reference to the next element in the list.
-
setNext
Description copied from interface:ConcurrentIntrusiveList.Element
Sets the reference to the next element in the list.- Specified by:
setNext
in interfaceConcurrentIntrusiveList.Element<RecordEventsSpanImpl>
- Parameters:
element
- the reference to the next element in the list.
-
getPrev
Description copied from interface:ConcurrentIntrusiveList.Element
Returns a reference to the previous element in the list.- Specified by:
getPrev
in interfaceConcurrentIntrusiveList.Element<RecordEventsSpanImpl>
- Returns:
- a reference to the previous element in the list.
-
setPrev
Description copied from interface:ConcurrentIntrusiveList.Element
Sets the reference to the previous element in the list.- Specified by:
setPrev
in interfaceConcurrentIntrusiveList.Element<RecordEventsSpanImpl>
- Parameters:
element
- the reference to the previous element in the list.
-