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 theSpan
class that records trace events.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
RecordEventsSpanImpl.AttributesWithCapacity
private static class
RecordEventsSpanImpl.EventWithNanoTime<T>
static interface
RecordEventsSpanImpl.StartEndHandler
Interface to handle the start and end operations for aSpan
only when theSpan
hasSpan.Options.RECORD_EVENTS
option.private static class
RecordEventsSpanImpl.TraceEvents<T>
-
Nested classes/interfaces inherited from class io.opencensus.trace.Span
Span.Kind, Span.Options
-
-
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description private
RecordEventsSpanImpl(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 void
addAnnotation(Annotation annotation)
Adds an annotation to theSpan
.void
addAnnotation(java.lang.String description, java.util.Map<java.lang.String,AttributeValue> attributes)
Adds an annotation to theSpan
.(package private) void
addChild()
void
addLink(Link link)
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
getEndNanoTime()
Returns the end nano time (seeSystem.nanoTime()
).private RecordEventsSpanImpl.TraceEvents<RecordEventsSpanImpl.EventWithNanoTime<Annotation>>
getInitializedAnnotations()
private RecordEventsSpanImpl.AttributesWithCapacity
getInitializedAttributes()
private RecordEventsSpanImpl.TraceEvents<Link>
getInitializedLinks()
private RecordEventsSpanImpl.TraceEvents<RecordEventsSpanImpl.EventWithNanoTime<MessageEvent>>
getInitializedNetworkEvents()
Span.Kind
getKind()
Returns the kind of thisSpan
.long
getLatencyNs()
Returns the latency of theSpan
in nanos.java.lang.String
getName()
Returns the name of theSpan
.RecordEventsSpanImpl
getNext()
Returns a reference to the next element in the list.RecordEventsSpanImpl
getPrev()
Returns a reference to the previous element in the list.boolean
getSampleToLocalSpanStore()
Returns if the name of thisSpan
must be register to theSampledSpanStore
.Status
getStatus()
Returns the status of theSpan
.private Status
getStatusWithDefault()
(package private) TimestampConverter
getTimestampConverter()
Returns theTimestampConverter
used by thisSpan
.void
putAttribute(java.lang.String key, AttributeValue value)
Sets an attribute to theSpan
.void
putAttributes(java.util.Map<java.lang.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
setStatus(Status status)
Sets theStatus
to theSpan
.static RecordEventsSpanImpl
startSpan(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.SpanData
toSpanData()
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
-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
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 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
@Nullable public Span.Kind getKind()
Returns the kind of thisSpan
.- Returns:
- the kind of this
Span
.
-
getTimestampConverter
@Nullable TimestampConverter getTimestampConverter()
Returns theTimestampConverter
used by thisSpan
.- Returns:
- the
TimestampConverter
used 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: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
public void putAttributes(java.util.Map<java.lang.String,AttributeValue> attributes)
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
public void addAnnotation(java.lang.String description, java.util.Map<java.lang.String,AttributeValue> attributes)
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
public void addAnnotation(Annotation annotation)
Description copied from class:Span
Adds an annotation to theSpan
.- Specified by:
addAnnotation
in classSpan
- Parameters:
annotation
- the annotations to add.
-
addMessageEvent
public void addMessageEvent(MessageEvent messageEvent)
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
public void addLink(Link link)
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
public void setStatus(Status status)
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
public void end(EndSpanOptions options)
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
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.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
public void setNext(@Nullable RecordEventsSpanImpl element)
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
@Nullable public RecordEventsSpanImpl 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
public void setPrev(@Nullable RecordEventsSpanImpl element)
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.
-
-