-
- All Implemented Interfaces:
-
com.datadog.trace.api.gateway.RequestContext,com.datadog.trace.api.internal.TraceSegment,com.datadog.trace.bootstrap.instrumentation.api.AgentSpan.Context,com.datadog.trace.bootstrap.instrumentation.api.ProfilerContext,java.io.Closeable,java.lang.AutoCloseable
public class DDSpanContext implements AgentSpan.Context, RequestContext, TraceSegment, ProfilerContext
SpanContext represents Span state that must propagate to descendant Spans and across process boundaries.
SpanContext is logically divided into two pieces: (1) the user-level "Baggage" that propagates across Span boundaries and (2) any Datadog fields that are needed to identify or contextualize the associated Span instance
-
-
Field Summary
Fields Modifier and Type Field Description public final static StringPRIORITY_SAMPLING_KEYpublic final static StringSAMPLE_RATE_KEYpublic final static StringSPAN_SAMPLING_MECHANISM_TAGpublic final static StringSPAN_SAMPLING_RULE_RATE_TAGpublic final static StringSPAN_SAMPLING_MAX_PER_SECOND_TAGprivate final PendingTracetraceprivate volatile Map<String, String>baggageItemsprivate final DDTraceIdtraceIdprivate final longspanIdprivate final longparentIdprivate volatile shorthttpStatusCodeprivate volatile StringserviceNameprivate volatile CharSequenceresourceNameprivate volatile byteresourceNamePriorityprivate volatile CharSequenceoperationNameprivate volatile CharSequencespanTypeprivate volatile booleanerrorFlagprivate volatile booleanmeasuredprivate volatile intsamplingPriorityprivate volatile CharSequenceoriginprivate final PropagationTagspropagationTagsprivate volatile PathwayContextpathwayContextprivate volatile BlockResponseFunctionblockResponseFunctionprivate volatile intencodedOperationNameprivate volatile intencodedResourceName
-
Constructor Summary
Constructors Constructor Description DDSpanContext(DDTraceId traceId, long spanId, long parentId, CharSequence parentServiceName, String serviceName, CharSequence operationName, CharSequence resourceName, int samplingPriority, CharSequence origin, Map<String, String> baggageItems, boolean errorFlag, CharSequence spanType, int tagsSize, PendingTrace trace, Object requestContextDataAppSec, Object requestContextDataIast, PathwayContext pathwayContext, boolean disableSamplingMechanismValidation, PropagationTags propagationTags)DDSpanContext(DDTraceId traceId, long spanId, long parentId, CharSequence parentServiceName, String serviceName, CharSequence operationName, CharSequence resourceName, int samplingPriority, CharSequence origin, Map<String, String> baggageItems, boolean errorFlag, CharSequence spanType, int tagsSize, PendingTrace trace, Object requestContextDataAppSec, Object requestContextDataIast, PathwayContext pathwayContext, boolean disableSamplingMechanismValidation, PropagationTags propagationTags, boolean injectBaggageAsTags)DDSpanContext(DDTraceId traceId, long spanId, long parentId, CharSequence parentServiceName, String serviceName, CharSequence operationName, CharSequence resourceName, int samplingPriority, CharSequence origin, Map<String, String> baggageItems, boolean errorFlag, CharSequence spanType, int tagsSize, PendingTrace trace, Object requestContextDataAppSec, Object requestContextDataIast, PathwayContext pathwayContext, boolean disableSamplingMechanismValidation, PropagationTags propagationTags, ProfilingContextIntegration profilingContextIntegration)DDSpanContext(DDTraceId traceId, long spanId, long parentId, CharSequence parentServiceName, String serviceName, CharSequence operationName, CharSequence resourceName, int samplingPriority, CharSequence origin, Map<String, String> baggageItems, boolean errorFlag, CharSequence spanType, int tagsSize, PendingTrace trace, Object requestContextDataAppSec, Object requestContextDataIast, Object CiVisibilityContextData, PathwayContext pathwayContext, boolean disableSamplingMechanismValidation, PropagationTags propagationTags, ProfilingContextIntegration profilingContextIntegration, boolean injectBaggageAsTags)
-
Method Summary
Modifier and Type Method Description PendingTracegetTrace()Get the span's trace. Map<String, String>getBaggageItems()DDTraceIdgetTraceId()Gets the TraceId of the span's trace. longgetSpanId()Gets the SpanId. longgetParentId()shortgetHttpStatusCode()voidsetHttpStatusCode(short statusCode)StringgetServiceName()voidsetServiceName(String serviceName)CharSequencegetResourceName()voidsetResourceName(CharSequence resourceName, byte priority)bytegetResourceNamePriority()CharSequencegetOperationName()voidsetOperationName(CharSequence operationName)CharSequencegetSpanType()voidsetSpanType(CharSequence spanType)booleangetErrorFlag()voidsetErrorFlag(boolean errorFlag, byte priority)voidsetMeasured(boolean measured)intgetSamplingPriority()Gets the trace sampling priority of the span's trace. booleansetSamplingPriority(int newPriority, int newMechanism)CharSequencegetOrigin()voidsetOrigin(CharSequence origin)PropagationTagsgetPropagationTags()PathwayContextgetPathwayContext()BlockResponseFunctiongetBlockResponseFunction()voidsetBlockResponseFunction(BlockResponseFunction blockResponseFunction)intgetEncodedOperationName()intgetEncodedResourceName()longgetRootSpanId()booleanhasResourceName()booleanisMeasured()booleanisTopLevel()voidforceKeep()voidsetSpanSamplingPriority(double rate, int limit)booleanlockSamplingPriority()Prevent future changes to the context's sampling priority. voidbeginEndToEnd()longgetEndToEndStartTime()voidsetBaggageItem(String key, String value)StringgetBaggageItem(String key)Iterable<Map.Entry<String, String>>baggageItems()RequestContextgetRequestContext()voidmergePathwayContext(PathwayContext pathwayContext)CoreTracergetTracer()voidsetMetric(CharSequence key, Number value)voidsetTag(String tag, Object value)Sets a tag to the span. ObjectunsafeGetTag(String tag)This is not thread-safe and must only be used when it can be guaranteed that the context willnot be mutated. Map<String, Object>getTags()voidprocessTagsAndBaggage(MetadataConsumer consumer, int longRunningVersion, List<AgentSpanLink> links)StringtoString()ObjectgetData(RequestContextSlot slot)RequestContext Implementation voidclose()TraceSegmentgetTraceSegment()voidsetTagTop(String key, Object value, boolean sanitize)TraceSegment Implementation voidsetTagCurrent(String key, Object value, boolean sanitize)Add a tag to the current span in this {@code TraceSegment}.voidsetDataTop(String key, Object value)Add data to the top of this {@code TraceSegment}.voideffectivelyBlocked()Mark the request as effectively blocked, by setting the tag appsec. voidsetDataCurrent(String key, Object value)Add data to the current span in this {@code TraceSegment}.-
Methods inherited from class com.datadog.trace.bootstrap.instrumentation.api.AgentSpan.Context
getTrace -
Methods inherited from class com.datadog.trace.api.gateway.RequestContext
getData -
Methods inherited from class java.io.Closeable
close -
Methods inherited from class com.datadog.trace.api.internal.TraceSegment
setTagCurrent, setTagTop -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
DDSpanContext
DDSpanContext(DDTraceId traceId, long spanId, long parentId, CharSequence parentServiceName, String serviceName, CharSequence operationName, CharSequence resourceName, int samplingPriority, CharSequence origin, Map<String, String> baggageItems, boolean errorFlag, CharSequence spanType, int tagsSize, PendingTrace trace, Object requestContextDataAppSec, Object requestContextDataIast, PathwayContext pathwayContext, boolean disableSamplingMechanismValidation, PropagationTags propagationTags)
-
DDSpanContext
DDSpanContext(DDTraceId traceId, long spanId, long parentId, CharSequence parentServiceName, String serviceName, CharSequence operationName, CharSequence resourceName, int samplingPriority, CharSequence origin, Map<String, String> baggageItems, boolean errorFlag, CharSequence spanType, int tagsSize, PendingTrace trace, Object requestContextDataAppSec, Object requestContextDataIast, PathwayContext pathwayContext, boolean disableSamplingMechanismValidation, PropagationTags propagationTags, boolean injectBaggageAsTags)
-
DDSpanContext
DDSpanContext(DDTraceId traceId, long spanId, long parentId, CharSequence parentServiceName, String serviceName, CharSequence operationName, CharSequence resourceName, int samplingPriority, CharSequence origin, Map<String, String> baggageItems, boolean errorFlag, CharSequence spanType, int tagsSize, PendingTrace trace, Object requestContextDataAppSec, Object requestContextDataIast, PathwayContext pathwayContext, boolean disableSamplingMechanismValidation, PropagationTags propagationTags, ProfilingContextIntegration profilingContextIntegration)
-
DDSpanContext
DDSpanContext(DDTraceId traceId, long spanId, long parentId, CharSequence parentServiceName, String serviceName, CharSequence operationName, CharSequence resourceName, int samplingPriority, CharSequence origin, Map<String, String> baggageItems, boolean errorFlag, CharSequence spanType, int tagsSize, PendingTrace trace, Object requestContextDataAppSec, Object requestContextDataIast, Object CiVisibilityContextData, PathwayContext pathwayContext, boolean disableSamplingMechanismValidation, PropagationTags propagationTags, ProfilingContextIntegration profilingContextIntegration, boolean injectBaggageAsTags)
-
-
Method Detail
-
getTrace
PendingTrace getTrace()
Get the span's trace.
-
getBaggageItems
Map<String, String> getBaggageItems()
-
getTraceId
DDTraceId getTraceId()
Gets the TraceId of the span's trace.
-
getSpanId
long getSpanId()
Gets the SpanId.
-
getParentId
long getParentId()
-
getHttpStatusCode
short getHttpStatusCode()
-
setHttpStatusCode
void setHttpStatusCode(short statusCode)
-
getServiceName
String getServiceName()
-
setServiceName
void setServiceName(String serviceName)
-
getResourceName
CharSequence getResourceName()
-
setResourceName
void setResourceName(CharSequence resourceName, byte priority)
-
getResourceNamePriority
byte getResourceNamePriority()
-
getOperationName
CharSequence getOperationName()
-
setOperationName
void setOperationName(CharSequence operationName)
-
getSpanType
CharSequence getSpanType()
-
setSpanType
void setSpanType(CharSequence spanType)
-
getErrorFlag
boolean getErrorFlag()
-
setErrorFlag
void setErrorFlag(boolean errorFlag, byte priority)
-
setMeasured
void setMeasured(boolean measured)
-
getSamplingPriority
int getSamplingPriority()
Gets the trace sampling priority of the span's trace.
Check PrioritySampling for possible values.
-
setSamplingPriority
boolean setSamplingPriority(int newPriority, int newMechanism)
-
getOrigin
CharSequence getOrigin()
-
setOrigin
void setOrigin(CharSequence origin)
-
getPropagationTags
PropagationTags getPropagationTags()
-
getPathwayContext
PathwayContext getPathwayContext()
-
getBlockResponseFunction
BlockResponseFunction getBlockResponseFunction()
-
setBlockResponseFunction
void setBlockResponseFunction(BlockResponseFunction blockResponseFunction)
-
getEncodedOperationName
int getEncodedOperationName()
-
getEncodedResourceName
int getEncodedResourceName()
-
getRootSpanId
long getRootSpanId()
-
hasResourceName
boolean hasResourceName()
-
isMeasured
boolean isMeasured()
-
isTopLevel
boolean isTopLevel()
-
forceKeep
void forceKeep()
-
setSpanSamplingPriority
void setSpanSamplingPriority(double rate, int limit)
-
lockSamplingPriority
@Deprecated() boolean lockSamplingPriority()
Prevent future changes to the context's sampling priority.
Used when a span is extracted or injected for propagation.
Has no effect if the sampling priority is unset.
-
beginEndToEnd
void beginEndToEnd()
-
getEndToEndStartTime
long getEndToEndStartTime()
-
setBaggageItem
void setBaggageItem(String key, String value)
-
getBaggageItem
String getBaggageItem(String key)
-
baggageItems
Iterable<Map.Entry<String, String>> baggageItems()
-
getRequestContext
RequestContext getRequestContext()
-
mergePathwayContext
void mergePathwayContext(PathwayContext pathwayContext)
-
getTracer
CoreTracer getTracer()
-
setMetric
void setMetric(CharSequence key, Number value)
-
setTag
void setTag(String tag, Object value)
Sets a tag to the span. Tags are not propagated to the children.
Existing tag value with the same value will be replaced. Setting a tag with a
{@code null}value will remove the tag from the span.- Parameters:
tag- The tag name.value- The nullable tag value.
-
unsafeGetTag
Object unsafeGetTag(String tag)
This is not thread-safe and must only be used when it can be guaranteed that the context willnot be mutated. This is internal API and must not be exposed to users.
-
processTagsAndBaggage
void processTagsAndBaggage(MetadataConsumer consumer, int longRunningVersion, List<AgentSpanLink> links)
-
getData
Object getData(RequestContextSlot slot)
RequestContext Implementation
-
close
void close()
-
getTraceSegment
TraceSegment getTraceSegment()
-
setTagCurrent
void setTagCurrent(String key, Object value, boolean sanitize)
Add a tag to the current span in this
{@code TraceSegment}. with optional key sanitization.- Parameters:
key- key of the tagvalue- value of the tagsanitize- indicates is key need to be sanitized
-
setDataTop
void setDataTop(String key, Object value)
Add data to the top of this
{@code TraceSegment}. The{@code toString}representation of the{@code value}must be valid top level JSON, i.e. an{@code Object}or an{@code Array}.- Parameters:
key- key of the datavalue- value of the data
-
effectivelyBlocked
void effectivelyBlocked()
Mark the request as effectively blocked, by setting the tag appsec.blocked
-
setDataCurrent
void setDataCurrent(String key, Object value)
Add data to the current span in this
{@code TraceSegment}. The{@code toString}representationof the{@code value}must be valid top level JSON, i.e. an{@code Object}or an{@code Array}.- Parameters:
key- key of the datavalue- value of the data
-
-
-
-