-
- All Implemented Interfaces:
-
com.datadog.trace.api.gateway.IGSpanInfo,com.datadog.trace.api.interceptor.MutableSpan,com.datadog.trace.api.profiling.TransientProfilingContextHolder,com.datadog.trace.bootstrap.instrumentation.api.AgentSpan,com.datadog.trace.bootstrap.instrumentation.api.AttachableWrapper,com.datadog.trace.core.CoreSpan
public class DDSpan implements AgentSpan, CoreSpan<DDSpan>, TransientProfilingContextHolder, AttachableWrapper
Represents a period of time. Associated information is stored in the SpanContext.
Spans are created by the buildSpan. This implementation adds some features according to the DD agent.
-
-
Field Summary
Fields Modifier and Type Field Description private final longstartTimeNanoprivate volatile longdurationNanoprivate volatile EndpointTrackerendpointTrackerprivate volatile Objectwrapperprivate volatile Flow.Action.RequestBlockingActionrequestBlockingActionprivate volatile intlongRunningVersionprivate final List<AgentSpanLink>links
-
Constructor Summary
Constructors Constructor Description DDSpan(String instrumentationName, long timestampMicro, DDSpanContext context, List<AgentSpanLink> links, InternalLogger internalLogger)Spans should be constructed using the builder, not by calling the constructor directly.
-
Method Summary
Modifier and Type Method Description longgetStartTimeNano()longgetDurationNano()EndpointTrackergetEndpointTracker()Retrieve the EndpointTracker instance associated with the corresponding local rootspan voidsetEndpointTracker(@NonNull() EndpointTracker endpointTracker)Attach an end-point tracker to the corresponding local root span. ObjectgetWrapper()Returns an attached OT/OTel wrapper or null. Flow.Action.RequestBlockingActiongetRequestBlockingAction()voidsetRequestBlockingAction(Flow.Action.RequestBlockingAction rba)voidsetLongRunningVersion(int longRunningVersion)List<AgentSpanLink>getLinks()booleanisFinished()voidfinish()voidfinish(long stopTimeMicros)final voidfinishWithDuration(long durationNano)voidbeginEndToEnd()Marks the start of a message pipeline where we want to track end-to-end processing time. voidfinishWithEndToEnd()Marks the end of a message pipeline where the final end-to-end processing time is recorded. final booleanphasedFinish()Finishes the span but does not publish it. final voidpublish()Publish a span that was previously finished by calling phasedFinish. DDSpansetError(boolean error)DDSpansetError(boolean error, byte priority)DDSpansetMeasured(boolean measured)DDSpanforceKeep(boolean forceKeep)booleanisForceKeep()final booleanisRootSpan()Check if the span is the root parent. AgentSpangetRootSpan()DDSpangetLocalRootSpan()Returns the root span for current the trace fragment. booleanisLocalRootSpan()Checks whether the span is also the local root span booleanisSameTrace(AgentSpan otherSpan)DDSpansetErrorMessage(String errorMessage)DDSpanaddThrowable(Throwable error)DDSpanaddThrowable(Throwable error, byte errorPriority)final DDSpansetTag(String tag, String value)final DDSpansetTag(String tag, boolean value)DDSpansetTag(String tag, int value)DDSpansetTag(String tag, long value)DDSpansetTag(String tag, double value)DDSpansetTag(String tag, Number value)DDSpansetMetric(CharSequence metric, int value)DDSpansetMetric(CharSequence name, float value)DDSpansetMetric(CharSequence metric, long value)DDSpansetMetric(CharSequence metric, double value)DDSpansetFlag(CharSequence name, boolean value)DDSpansetTag(String tag, CharSequence value)DDSpansetTag(String tag, Object value)DDSpanremoveTag(String tag)ObjectgetTag(String tag)final DDSpanContextcontext()final StringgetBaggageItem(String key)final DDSpansetBaggageItem(String key, String value)AgentSpansetHttpStatusCode(int statusCode)shortgetHttpStatusCode()CharSequencegetOrigin()final DDSpansetOperationName(CharSequence operationName)final DDSpansetServiceName(String serviceName)final DDSpansetResourceName(CharSequence resourceName)final DDSpansetResourceName(CharSequence resourceName, byte priority)Implementation note: two calls with the same priority will result in the second resource namebeing used booleaneligibleForDropping()RequestContextgetRequestContext()RequestContext for the Instrumentation Gateway IntegerforceSamplingDecision()final DDSpansetSamplingPriority(int newPriority)final DDSpansetSamplingPriority(int newPriority, int samplingMechanism)Set the sampling priority of the root span of this span's traceHas no effect if the span priority has been propagated (injected or extracted). DDSpansetSamplingPriority(int samplingPriority, CharSequence rate, double sampleRate, int samplingMechanism)DDSpansetSpanSamplingPriority(double rate, int limit)final DDSpansetSpanType(CharSequence type)longgetStartTime()StringgetServiceName()DDTraceIdgetTraceId()longgetSpanId()longgetParentId()CharSequencegetResourceName()CharSequencegetOperationName()CharSequencegetSpanName()voidsetSpanName(CharSequence spanName)booleanhasResourceName()Deprecated in favor of setResourceName(final CharSequence resourceName, byte priority) or usinggetResourceNamePriority() for comparisons. bytegetResourceNamePriority()IntegergetSamplingPriority()intsamplingPriority()StringgetSpanType()Map<String, Object>getTags()CharSequencegetType()voidprocessTagsAndBaggage(MetadataConsumer consumer)booleanisError()intgetError()<U> UgetTag(CharSequence name, U defaultValue)<U> UgetTag(CharSequence name)booleanhasSamplingPriority()booleanisMeasured()booleanisTopLevel()Map<String, String>getBaggage()StringtoString()voidattachWrapper(Object wrapper)Attaches a OT/OTel wrapper to a tracer object. TraceConfigtraceConfig()voidaddLink(AgentSpanLink link)-
Methods inherited from class com.datadog.trace.bootstrap.instrumentation.api.AgentSpan
addThrowable, addThrowable, context, finish, finishWithDuration, getBaggageItem, getLocalRootSpan, getTag, isSameTrace, setBaggageItem, setError, setError, setErrorMessage, setMeasured, setMetric, setMetric, setMetric, setResourceName, setResourceName, setSamplingPriority, setSpanName, setSpanType, setTag, setTag, setTag, setTag, setTag, setTag, setTag, setTag -
Methods inherited from class com.datadog.trace.api.interceptor.MutableSpan
getLocalRootSpan, getRootSpan, setError, setMetric, setMetric, setMetric, setOperationName, setResourceName, setSamplingPriority, setServiceName, setSpanType, setTag, setTag, setTag -
Methods inherited from class com.datadog.trace.core.CoreSpan
addThrowable, getLocalRootSpan, processTagsAndBaggage, removeTag, setErrorMessage, setFlag, setMeasured, setMetric, setMetric, setMetric, setMetric, setSamplingPriority, setSamplingPriority, setSpanSamplingPriority, setTag, setTag, setTag, setTag, setTag, setTag, setTag, setTag -
Methods inherited from class com.datadog.trace.bootstrap.instrumentation.api.AttachableWrapper
attachWrapper -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
DDSpan
DDSpan(String instrumentationName, long timestampMicro, DDSpanContext context, List<AgentSpanLink> links, InternalLogger internalLogger)
Spans should be constructed using the builder, not by calling the constructor directly.- Parameters:
instrumentationName- instrumentation that creates the spantimestampMicro- if greater than zero, use this time instead of the current timecontext- the context used for the span
-
-
Method Detail
-
getStartTimeNano
long getStartTimeNano()
-
getDurationNano
long getDurationNano()
-
getEndpointTracker
@Nullable() EndpointTracker getEndpointTracker()
Retrieve the EndpointTracker instance associated with the corresponding local rootspan
-
setEndpointTracker
void setEndpointTracker(@NonNull() EndpointTracker endpointTracker)
Attach an end-point tracker to the corresponding local root span. When this method is calledmultiple times the last invocation will 'win'
- Parameters:
endpointTracker- the end-point tracker instance
-
getWrapper
Object getWrapper()
Returns an attached OT/OTel wrapper or null.
-
getRequestBlockingAction
Flow.Action.RequestBlockingAction getRequestBlockingAction()
-
setRequestBlockingAction
void setRequestBlockingAction(Flow.Action.RequestBlockingAction rba)
-
setLongRunningVersion
void setLongRunningVersion(int longRunningVersion)
-
getLinks
List<AgentSpanLink> getLinks()
-
isFinished
boolean isFinished()
-
finish
void finish()
-
finish
void finish(long stopTimeMicros)
-
finishWithDuration
final void finishWithDuration(long durationNano)
-
beginEndToEnd
void beginEndToEnd()
Marks the start of a message pipeline where we want to track end-to-end processing time.
-
finishWithEndToEnd
void finishWithEndToEnd()
Marks the end of a message pipeline where the final end-to-end processing time is recorded.
Note: this will also finish the span and publish it.
-
phasedFinish
final boolean phasedFinish()
Finishes the span but does not publish it. The publish method MUST be called onceotherwise the trace will not be reported.
-
publish
final void publish()
Publish a span that was previously finished by calling phasedFinish. Must be calledonce and only once per span.
-
setMeasured
DDSpan setMeasured(boolean measured)
-
isForceKeep
boolean isForceKeep()
-
isRootSpan
final boolean isRootSpan()
Check if the span is the root parent. It means that the traceId is the same as the spanId. Inthe context of distributed tracing this will return true if an only if this is the applicationinitializing the trace.
-
getRootSpan
@Deprecated() AgentSpan getRootSpan()
-
getLocalRootSpan
DDSpan getLocalRootSpan()
Returns the root span for current the trace fragment. In the context of distributed tracingthis method returns the root span only for the fragment generated by the currently tracedapplication.
-
isLocalRootSpan
boolean isLocalRootSpan()
Checks whether the span is also the local root span
-
isSameTrace
boolean isSameTrace(AgentSpan otherSpan)
-
setErrorMessage
DDSpan setErrorMessage(String errorMessage)
-
addThrowable
DDSpan addThrowable(Throwable error)
-
addThrowable
DDSpan addThrowable(Throwable error, byte errorPriority)
-
setMetric
DDSpan setMetric(CharSequence metric, int value)
-
setMetric
DDSpan setMetric(CharSequence name, float value)
-
setMetric
DDSpan setMetric(CharSequence metric, long value)
-
setMetric
DDSpan setMetric(CharSequence metric, double value)
-
setFlag
DDSpan setFlag(CharSequence name, boolean value)
-
setTag
DDSpan setTag(String tag, CharSequence value)
-
context
@NonNull() final DDSpanContext context()
-
getBaggageItem
final String getBaggageItem(String key)
-
setBaggageItem
final DDSpan setBaggageItem(String key, String value)
-
setHttpStatusCode
AgentSpan setHttpStatusCode(int statusCode)
-
getHttpStatusCode
short getHttpStatusCode()
-
getOrigin
CharSequence getOrigin()
-
setOperationName
final DDSpan setOperationName(CharSequence operationName)
-
setServiceName
final DDSpan setServiceName(String serviceName)
-
setResourceName
final DDSpan setResourceName(CharSequence resourceName)
-
setResourceName
final DDSpan setResourceName(CharSequence resourceName, byte priority)
Implementation note: two calls with the same priority will result in the second resource namebeing used
-
eligibleForDropping
boolean eligibleForDropping()
-
getRequestContext
RequestContext getRequestContext()
RequestContext for the Instrumentation Gateway
-
forceSamplingDecision
Integer forceSamplingDecision()
-
setSamplingPriority
@Deprecated() final DDSpan setSamplingPriority(int newPriority)
-
setSamplingPriority
final DDSpan setSamplingPriority(int newPriority, int samplingMechanism)
Set the sampling priority of the root span of this span's trace
Has no effect if the span priority has been propagated (injected or extracted).
-
setSamplingPriority
DDSpan setSamplingPriority(int samplingPriority, CharSequence rate, double sampleRate, int samplingMechanism)
-
setSpanSamplingPriority
DDSpan setSpanSamplingPriority(double rate, int limit)
-
setSpanType
final DDSpan setSpanType(CharSequence type)
-
getStartTime
long getStartTime()
-
getServiceName
String getServiceName()
-
getTraceId
DDTraceId getTraceId()
-
getSpanId
long getSpanId()
-
getParentId
long getParentId()
-
getResourceName
CharSequence getResourceName()
-
getOperationName
CharSequence getOperationName()
-
getSpanName
CharSequence getSpanName()
-
setSpanName
void setSpanName(CharSequence spanName)
-
hasResourceName
boolean hasResourceName()
Deprecated in favor of setResourceName(final CharSequence resourceName, byte priority) or usinggetResourceNamePriority() for comparisons.
-
getResourceNamePriority
byte getResourceNamePriority()
-
getSamplingPriority
Integer getSamplingPriority()
-
samplingPriority
int samplingPriority()
-
getSpanType
String getSpanType()
-
getType
CharSequence getType()
-
processTagsAndBaggage
void processTagsAndBaggage(MetadataConsumer consumer)
-
isError
boolean isError()
-
getError
int getError()
-
getTag
<U> U getTag(CharSequence name, U defaultValue)
-
getTag
<U> U getTag(CharSequence name)
-
hasSamplingPriority
boolean hasSamplingPriority()
-
isMeasured
boolean isMeasured()
-
isTopLevel
boolean isTopLevel()
-
getBaggage
Map<String, String> getBaggage()
-
attachWrapper
void attachWrapper(Object wrapper)
Attaches a OT/OTel wrapper to a tracer object.
-
traceConfig
TraceConfig traceConfig()
-
addLink
void addLink(AgentSpanLink link)
-
-
-
-