-
- All Implemented Interfaces:
-
com.datadog.trace.bootstrap.instrumentation.api.AgentTrace,com.datadog.trace.core.PendingTraceBuffer.Element
public class PendingTrace implements AgentTrace, PendingTraceBuffer.Element
This class implements the following data flow rules when a Span is finished:
- Immediate Write
- pending ref count == 0 && trace not already written
- not root span && size exceeds partial flush
- Delayed Write
- is root span && pending ref count > 0
- not root span && pending ref count > 0 && trace already written
Delayed write is handled by PendingTraceBuffer.
When the long-running traces feature is enabled, periodic writes are triggered by the PendingTraceBuffer in addition to the other write conditions. Running spans are also written in that case.
-
-
Field Summary
Fields Modifier and Type Field Description private final TimeSourcetimeSourceprivate volatile intpendingReferenceCountprivate volatile DDSpanrootSpanprivate volatile longendToEndStartTime
-
Method Summary
Modifier and Type Method Description TimeSourcegetTimeSource()intgetPendingReferenceCount()DDSpangetRootSpan()longgetEndToEndStartTime()longgetCurrentTimeNano()Current timestamp in nanoseconds; 'touches' the trace by updating lastReferenced. voidtouch()booleanlastReferencedNanosAgo(long nanos)IntegerevaluateSamplingPriority()booleancompareAndSetLongRunningState(int expected, int newState)longoldestFinishedTime()voidregisterContinuation(AgentScope.Continuation continuation)When using continuations, it's possible one may be used after all existing spans are otherwisecompleted, so we need to wait till continuations are de-referenced before reporting. voidcancelContinuation(AgentScope.Continuation continuation)voidwrite()Important to note: may be called multiple times. intenqueueSpansToWrite(List<DDSpan> trace, boolean writeRunningSpans)intsize()voidbeginEndToEnd()longgetLastWriteTime()longgetRunningTraceStartTime()voidsetLastWriteTime(long now)booleanisRootSpanWritten()booleansetEnqueued(boolean enqueued)Set or clear if the {@code Element}is enqueued.booleanwriteOnBufferFull()Called when the pendingTraceBuffer is full and a pendingTrace is offered. static longgetDurationNano(CoreSpan<out Object> span)Calculates the duration of a span in nanoseconds for the transport layerAs the internal duration of a running span is 0, the duration is set to the differencebetween the span's start time and the time of the write trigger. voidsetSamplingPriorityIfNecessary()booleansample(DDSpan spanToSample)-
-
Method Detail
-
getTimeSource
TimeSource getTimeSource()
-
getPendingReferenceCount
int getPendingReferenceCount()
-
getRootSpan
DDSpan getRootSpan()
-
getEndToEndStartTime
long getEndToEndStartTime()
-
getCurrentTimeNano
long getCurrentTimeNano()
Current timestamp in nanoseconds; 'touches' the trace by updating lastReferenced.
Note: This method uses trace start time as a reference and it gets time with nanosecondprecision after that. This means time measured within same Trace in different Spans isrelatively correct with nanosecond precision.
-
touch
void touch()
-
lastReferencedNanosAgo
boolean lastReferencedNanosAgo(long nanos)
-
evaluateSamplingPriority
Integer evaluateSamplingPriority()
-
compareAndSetLongRunningState
boolean compareAndSetLongRunningState(int expected, int newState)
-
oldestFinishedTime
long oldestFinishedTime()
-
registerContinuation
void registerContinuation(AgentScope.Continuation continuation)
When using continuations, it's possible one may be used after all existing spans are otherwisecompleted, so we need to wait till continuations are de-referenced before reporting.
-
cancelContinuation
void cancelContinuation(AgentScope.Continuation continuation)
-
write
void write()
Important to note: may be called multiple times.
-
enqueueSpansToWrite
int enqueueSpansToWrite(List<DDSpan> trace, boolean writeRunningSpans)
-
size
int size()
-
beginEndToEnd
void beginEndToEnd()
-
getLastWriteTime
long getLastWriteTime()
-
getRunningTraceStartTime
long getRunningTraceStartTime()
-
setLastWriteTime
void setLastWriteTime(long now)
-
isRootSpanWritten
boolean isRootSpanWritten()
-
setEnqueued
boolean setEnqueued(boolean enqueued)
Set or clear if the
{@code Element}is enqueued. Needs to be atomic.- Parameters:
enqueued- true if the enqueued state should be set or false if it should be cleared
-
writeOnBufferFull
boolean writeOnBufferFull()
Called when the pendingTraceBuffer is full and a pendingTrace is offered.
If the pendingTrace is not sent to the LongRunningTracesTracker, it will be immediatelywritten. Otherwise, the pendingTrace won't be tracked and no write is triggered.
-
getDurationNano
static long getDurationNano(CoreSpan<out Object> span)
Calculates the duration of a span in nanoseconds for the transport layer
As the internal duration of a running span is 0, the duration is set to the differencebetween the span's start time and the time of the write trigger.
-
setSamplingPriorityIfNecessary
void setSamplingPriorityIfNecessary()
-
-
-
-