Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -14,8 +14,8 @@ class CompositePropagator implements Propagator {

@Override
public <C> void inject(Context context, C carrier, CarrierSetter<C> setter) {
for (Propagator propagator : this.propagators) {
propagator.inject(context, carrier, setter);
for (int i = this.propagators.length - 1; i >= 0; i--) {
this.propagators[i].inject(context, carrier, setter);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public static Propagator noop() {
* Creates a composite propagator.
*
* @param propagators the elements that composes the returned propagator.
* @return the composite propagator that will apply the propagators in their given order.
* @return the composite propagator that will apply the propagators in their given order for
* context extraction, and reverse given order for context injection.
*/
public static Propagator composite(Propagator... propagators) {
if (propagators.length == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import datadog.trace.api.InstrumenterConfig;
import datadog.trace.api.StatsDClient;
import datadog.trace.api.TraceConfig;
import datadog.trace.api.TracePropagationStyle;
import datadog.trace.api.config.GeneralConfig;
import datadog.trace.api.experimental.DataStreamsCheckpointer;
import datadog.trace.api.flare.TracerFlare;
Expand Down Expand Up @@ -79,7 +78,6 @@
import datadog.trace.common.writer.WriterFactory;
import datadog.trace.common.writer.ddintake.DDIntakeTraceInterceptor;
import datadog.trace.context.TraceScope;
import datadog.trace.core.datastreams.DataStreamContextInjector;
import datadog.trace.core.datastreams.DataStreamsMonitoring;
import datadog.trace.core.datastreams.DefaultDataStreamsMonitoring;
import datadog.trace.core.flare.TracerFlarePoller;
Expand Down Expand Up @@ -719,13 +717,8 @@ private CoreTracer(
HttpCodec.Extractor builtExtractor =
extractor == null ? HttpCodec.createExtractor(config, this::captureTraceConfig) : extractor;
builtExtractor = this.dataStreamsMonitoring.extractor(builtExtractor);
// Create all HTTP injectors plus the DSM one
Map<TracePropagationStyle, HttpCodec.Injector> injectors =
HttpCodec.allInjectorsFor(config, invertMap(baggageMapping));
DataStreamContextInjector dataStreamContextInjector = this.dataStreamsMonitoring.injector();
// Store all propagators to propagation
this.propagation =
new CorePropagation(builtExtractor, injector, injectors, dataStreamContextInjector);
this.propagation = new CorePropagation(builtExtractor, this.dataStreamsMonitoring.injector());

// Check if standalone AppSec is enabled:
// If enabled, use the standalone AppSec propagator by default that will limit tracing concern
Expand Down
Original file line number Diff line number Diff line change
@@ -1,81 +1,27 @@
package datadog.trace.core.propagation;

import datadog.trace.api.Config;
import datadog.trace.api.TracePropagationStyle;
import datadog.trace.bootstrap.instrumentation.api.AgentPropagation;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.bootstrap.instrumentation.api.AgentSpanContext;
import datadog.trace.core.DDSpanContext;
import datadog.trace.core.datastreams.DataStreamContextInjector;
import java.util.LinkedHashMap;
import java.util.Map;

public class CorePropagation implements AgentPropagation {
private final HttpCodec.Injector injector;
private final Map<TracePropagationStyle, HttpCodec.Injector> injectors;
private final DataStreamContextInjector dataStreamContextInjector;
private final HttpCodec.Extractor extractor;

/**
* Constructor
*
* @param extractor The context extractor.
* @param defaultInjector The default injector when no {@link TracePropagationStyle} given.
* @param injectors All the other injectors available for context injection.
* @param dataStreamContextInjector The DSM context injector, as a specific object until generic
* context injection is available.
*/
public CorePropagation(
HttpCodec.Extractor extractor,
HttpCodec.Injector defaultInjector,
Map<TracePropagationStyle, HttpCodec.Injector> injectors,
DataStreamContextInjector dataStreamContextInjector) {
HttpCodec.Extractor extractor, DataStreamContextInjector dataStreamContextInjector) {
this.extractor = extractor;
this.injector = defaultInjector;
this.injectors = injectors;
this.dataStreamContextInjector = dataStreamContextInjector;
}

@Override
public <C> void inject(final AgentSpan span, final C carrier, final Setter<C> setter) {
inject(span.context(), carrier, setter, null);
}

@Override
public <C> void inject(AgentSpanContext context, C carrier, Setter<C> setter) {
inject(context, carrier, setter, null);
}

@Override
public <C> void inject(AgentSpan span, C carrier, Setter<C> setter, TracePropagationStyle style) {
inject(span.context(), carrier, setter, style);
}

private <C> void inject(
AgentSpanContext context, C carrier, Setter<C> setter, TracePropagationStyle style) {
if (!(context instanceof DDSpanContext)) {
return;
}

final DDSpanContext ddSpanContext = (DDSpanContext) context;
ddSpanContext.getTraceCollector().setSamplingPriorityIfNecessary();

/**
* If the experimental appsec standalone feature is enabled and appsec propagation is disabled
* (no ASM events), stop propagation
*/
if (Config.get().isAppSecStandaloneEnabled()
&& !ddSpanContext.getPropagationTags().isAppsecPropagationEnabled()) {
return;
}

if (null == style) {
injector.inject(ddSpanContext, carrier, setter);
} else {
injectors.get(style).inject(ddSpanContext, carrier, setter);
}
}

@Override
public <C> void injectPathwayContext(
AgentSpan span, C carrier, Setter<C> setter, LinkedHashMap<String, String> sortedTags) {
Expand All @@ -100,9 +46,4 @@ public <C> void injectPathwayContextWithoutSendingStats(
this.dataStreamContextInjector.injectPathwayContextWithoutSendingStats(
span, carrier, setter, sortedTags);
}

@Override
public <C> AgentSpanContext.Extracted extract(final C carrier, final ContextVisitor<C> getter) {
return extractor.extract(carrier, getter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import datadog.trace.common.sampling.Sampler
import datadog.trace.common.writer.DDAgentWriter
import datadog.trace.common.writer.ListWriter
import datadog.trace.common.writer.LoggingWriter
import datadog.trace.core.datastreams.DataStreamContextExtractor
import datadog.trace.core.propagation.HttpCodec
import datadog.trace.core.tagprocessor.TagsPostProcessorFactory
import datadog.trace.core.test.DDCoreSpecification
import okhttp3.HttpUrl
Expand Down Expand Up @@ -55,9 +53,6 @@ class CoreTracerTest extends DDCoreSpecification {
tracer.writer instanceof DDAgentWriter
tracer.statsDClient != null && tracer.statsDClient != StatsDClient.NO_OP

tracer.propagate().injector instanceof HttpCodec.CompoundInjector
tracer.propagate().extractor instanceof DataStreamContextExtractor

cleanup:
tracer.close()
}
Expand Down
Loading
Loading