Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class TypeConverterTest extends InstrumentationSpecification {
null,
null,
NoopPathwayContext.INSTANCE,
false,
PropagationTags.factory().empty()) {
@Override void setServiceName(final String serviceName) {
// override this method that is called from the DDSpanContext constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class TypeConverterTest extends InstrumentationSpecification {
null,
null,
NoopPathwayContext.INSTANCE,
false,
PropagationTags.factory().empty()) {
@Override void setServiceName(final String serviceName) {
// override this method that is called from the DDSpanContext constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class TypeConverterTest extends InstrumentationSpecification {
null,
null,
NoopPathwayContext.INSTANCE,
false,
PropagationTags.factory().empty()) {
@Override void setServiceName(final String serviceName) {
// override this method that is called from the DDSpanContext constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public void init(Blackhole blackhole) {
null,
null,
NoopPathwayContext.INSTANCE,
false,
propagationTags);
DDSpanHelper.setAllTags(rootContext, tags);
DDSpan root = DDSpanHelper.create("benchmark", System.currentTimeMillis() * 1000, rootContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public void init(TraceCounters counters, Blackhole blackhole) {
null,
null,
NoopPathwayContext.INSTANCE,
false,
null),
null);
span =
Expand All @@ -85,7 +84,6 @@ public void init(TraceCounters counters, Blackhole blackhole) {
null,
null,
NoopPathwayContext.INSTANCE,
false,
null),
null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ private DDSpan createSpanWithOrigin(int iter, final String origin) {
null,
null,
NoopPathwayContext.INSTANCE,
false,
null),
null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ public void setUp(Blackhole blackhole) {
null,
null,
null,
false,
propagationTags);
}

Expand Down
15 changes: 12 additions & 3 deletions dd-trace-core/src/main/java/datadog/trace/core/CoreTracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,18 @@ public void updatePreferredServiceName(String serviceName, CharSequence source)
ServiceNameCollector.get().addService(serviceName);
}

boolean isSamplingMechanismValidationDisabled() {
return disableSamplingMechanismValidation;
}

boolean isInjectBaggageAsTags() {
return injectBaggageAsTags;
}

boolean isInjectLinksAsTags() {
return injectLinksAsTags;
}

PropagationTags.Factory getPropagationTagsFactory() {
return propagationTagsFactory;
}
Expand Down Expand Up @@ -2347,11 +2359,8 @@ protected static final DDSpanContext buildSpanContext(
requestContextDataIast,
ciVisibilityContextData,
pathwayContext,
tracer.disableSamplingMechanismValidation,
propagationTags,
tracer.profilingContextIntegration,
tracer.injectBaggageAsTags,
tracer.injectLinksAsTags,
mergedTracerTagsNeedsIntercept ? null : mergedTracerTags);

// By setting the tags on the context we apply decorators to any tags that have been set via
Expand Down
93 changes: 13 additions & 80 deletions dd-trace-core/src/main/java/datadog/trace/core/DDSpanContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ public class DDSpanContext implements AgentSpanContext, ProfilerContext {
/** Baggage is associated with the whole trace and shared with other spans */
private volatile Map<String, String> baggageItems;

private final Baggage w3cBaggage;

// Not Shared with other span contexts
private final DDTraceId traceId;
private final long spanId;
Expand Down Expand Up @@ -166,8 +164,6 @@ public class DDSpanContext implements AgentSpanContext, ProfilerContext {

private volatile boolean topLevel;

private final boolean disableSamplingMechanismValidation;

/**
* This span's own propagation tags, when they differ from the trace's. Only a non-root span that
* is the target of a write (e.g. {@code _dd.p.ts}) gets one. Access via {@link
Expand All @@ -183,8 +179,6 @@ public class DDSpanContext implements AgentSpanContext, ProfilerContext {
private volatile PathwayContext pathwayContext;

private final ProfilingContextIntegration profilingContextIntegration;
private final boolean injectBaggageAsTags;
private final boolean injectLinksAsTags;
private volatile int encodedOperationName;
private volatile int encodedResourceName;

Expand Down Expand Up @@ -213,7 +207,6 @@ public DDSpanContext(
final Object requestContextDataAppSec,
final Object requestContextDataIast,
final PathwayContext pathwayContext,
final boolean disableSamplingMechanismValidation,
final PropagationTags propagationTags) {
this(
traceId,
Expand All @@ -236,62 +229,8 @@ public DDSpanContext(
requestContextDataIast,
null,
pathwayContext,
disableSamplingMechanismValidation,
propagationTags,
ProfilingContextIntegration.NoOp.INSTANCE,
true,
true,
null);
}

public DDSpanContext(
final DDTraceId traceId,
final long spanId,
final long parentId,
final CharSequence parentServiceName,
final String serviceName,
final CharSequence operationName,
final CharSequence resourceName,
final int samplingPriority,
final CharSequence origin,
final Map<String, String> baggageItems,
final boolean errorFlag,
final CharSequence spanType,
final int tagsSize,
final TraceCollector traceCollector,
final Object requestContextDataAppSec,
final Object requestContextDataIast,
final PathwayContext pathwayContext,
final boolean disableSamplingMechanismValidation,
final PropagationTags propagationTags,
final boolean injectBaggageAsTags,
final boolean injectLinksAsTags) {
this(
traceId,
spanId,
parentId,
parentServiceName,
null,
serviceName,
operationName,
resourceName,
samplingPriority,
origin,
baggageItems,
null,
errorFlag,
spanType,
tagsSize,
traceCollector,
requestContextDataAppSec,
requestContextDataIast,
null,
pathwayContext,
disableSamplingMechanismValidation,
propagationTags,
ProfilingContextIntegration.NoOp.INSTANCE,
injectBaggageAsTags,
injectLinksAsTags,
null);
}

Expand All @@ -317,11 +256,8 @@ public DDSpanContext(
final Object requestContextDataIast,
final Object CiVisibilityContextData,
final PathwayContext pathwayContext,
final boolean disableSamplingMechanismValidation,
final PropagationTags propagationTags,
final ProfilingContextIntegration profilingContextIntegration,
final boolean injectBaggageAsTags,
final boolean injectLinksAsTags) {
final ProfilingContextIntegration profilingContextIntegration) {
this(
traceId,
spanId,
Expand All @@ -343,11 +279,8 @@ public DDSpanContext(
requestContextDataIast,
CiVisibilityContextData,
pathwayContext,
disableSamplingMechanismValidation,
propagationTags,
profilingContextIntegration,
injectBaggageAsTags,
injectLinksAsTags,
null);
}

Expand All @@ -372,11 +305,8 @@ public DDSpanContext(
final Object requestContextDataIast,
final Object CiVisibilityContextData,
final PathwayContext pathwayContext,
final boolean disableSamplingMechanismValidation,
final PropagationTags propagationTags,
final ProfilingContextIntegration profilingContextIntegration,
final boolean injectBaggageAsTags,
final boolean injectLinksAsTags,
final TagMap readThroughParent) {

assert traceCollector != null;
Expand All @@ -394,7 +324,9 @@ public DDSpanContext(
} else {
this.baggageItems = new ConcurrentHashMap<>(baggageItems);
}
this.w3cBaggage = w3cBaggage;
if (w3cBaggage != null) {
traceCollector.initW3CBaggage(w3cBaggage);
}

if (requestContextDataAppSec != null
|| requestContextDataIast != null
Expand Down Expand Up @@ -433,16 +365,13 @@ public DDSpanContext(
this.threadId = current.getId();
this.threadName = THREAD_NAMES.computeIfAbsent(current.getName(), Functions.UTF8_ENCODE);

this.disableSamplingMechanismValidation = disableSamplingMechanismValidation;
if (propagationTags != null) {
propagationTags.updateTraceIdHighOrderBits(this.traceId.toHighOrderLong());
if (traceCollector.initPropagationTags(propagationTags) != propagationTags) {
// the trace already has propagation tags, so these are this span's own
this.propagationTags = propagationTags;
}
}
this.injectBaggageAsTags = injectBaggageAsTags;
this.injectLinksAsTags = injectLinksAsTags;
if (origin != null) {
setOrigin(origin);
}
Expand Down Expand Up @@ -808,7 +737,7 @@ private boolean validateSamplingPriority(final int newPriority, final int newMec
return false;
}
if (!SamplingMechanism.validateWithSamplingPriority(newMechanism, newPriority)) {
if (disableSamplingMechanismValidation) {
if (traceCollector.getTracer().isSamplingMechanismValidationDisabled()) {
log.debug(
"{}: Bypassing setting setSamplingPriority check ("
+ TracerConfig.SAMPLING_MECHANISM_VALIDATION_DISABLED
Expand Down Expand Up @@ -1541,7 +1470,8 @@ void earlyProcessTags(AppendableSpanLinks links) {
*/
void processTagsAndBaggage(
final MetadataConsumer consumer, int longRunningVersion, DDSpan restrictedSpan, int options) {
boolean injectLinksAsTags = this.injectLinksAsTags && (options & STRUCTURED_LINKS) == 0;
boolean injectLinksAsTags =
traceCollector.getTracer().isInjectLinksAsTags() && (options & STRUCTURED_LINKS) == 0;
boolean injectEventsAsTags = (options & STRUCTURED_EVENTS) == 0;
PropagationTags serializedPropagationTags;
if ((options & ROOT_PROPAGATION_TAGS) != 0) {
Expand Down Expand Up @@ -1581,10 +1511,12 @@ void processTagsAndBaggage(

// Baggage
Map<String, String> baggageItemsWithPropagationTags;
if (this.injectBaggageAsTags) {
if (traceCollector.getTracer().isInjectBaggageAsTags()) {
baggageItemsWithPropagationTags = new HashMap<>(baggageItems);
// W3C baggage is only extracted onto the local root
Baggage w3cBaggage = isLocalRoot() ? traceCollector.getW3CBaggage() : null;
if (w3cBaggage != null) {
injectW3CBaggageTags(baggageItemsWithPropagationTags);
injectW3CBaggageTags(baggageItemsWithPropagationTags, w3cBaggage);
}
if (serializedPropagationTags != null) {
serializedPropagationTags.fillTagMap(baggageItemsWithPropagationTags);
Expand Down Expand Up @@ -1709,7 +1641,8 @@ private static void appendJsonString(StringBuilder builder, String value) {
builder.append('"');
}

void injectW3CBaggageTags(Map<String, String> baggageItemsWithPropagationTags) {
void injectW3CBaggageTags(
Map<String, String> baggageItemsWithPropagationTags, Baggage w3cBaggage) {
List<String> baggageTagKeys = Config.get().getTraceBaggageTagKeys();
if (baggageTagKeys.isEmpty()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import datadog.trace.api.sampling.PrioritySampling;
import datadog.trace.api.time.TimeSource;
import datadog.trace.bootstrap.instrumentation.api.AgentTraceCollector;
import datadog.trace.bootstrap.instrumentation.api.Baggage;
import datadog.trace.bootstrap.instrumentation.api.ClientIpAddressData;
import datadog.trace.common.sampling.PrioritySampler;
import datadog.trace.core.propagation.PropagationTags;
Expand Down Expand Up @@ -73,6 +74,9 @@ enum PublishState {
/** The origin of the trace. (eg. Synthetics, CI App) */
private volatile CharSequence origin;

/** The W3C baggage extracted with the trace, held for the local root's serialization. */
private volatile Baggage w3cBaggage;

private volatile BlockResponseFunction blockResponseFunction;
private volatile ClientIpAddressData clientIpAddressData;

Expand Down Expand Up @@ -162,6 +166,17 @@ PropagationTags initPropagationTags(PropagationTags propagationTags) {
: this.propagationTags;
}

/** Sets the extracted W3C baggage unless already set. */
void initW3CBaggage(Baggage w3cBaggage) {
if (this.w3cBaggage == null) {
this.w3cBaggage = w3cBaggage;
}
}

Baggage getW3CBaggage() {
return w3cBaggage;
}

CharSequence getOrigin() {
return origin;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ DDSpan realSpan() throws Exception {
null,
null,
NoopPathwayContext.INSTANCE,
false,
PropagationTags.factory().empty());
Constructor<DDSpan> ctor =
DDSpan.class.getDeclaredConstructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,8 @@ protected DDSpan buildSpan(
null,
ciVisibilityContextData,
NoopPathwayContext.INSTANCE,
false,
propagationTags,
ProfilingContextIntegration.NoOp.INSTANCE,
true,
true);
ProfilingContextIntegration.NoOp.INSTANCE);

DDSpan span = DDSpan.create("test", timestamp, context, null);
for (Map.Entry<String, Object> entry : tags.entrySet()) {
Expand Down
Loading
Loading