Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
updating to handle behaviorExtract=IGNORE in CoreTracer rather than B…
…aggagePropagator
  • Loading branch information
mhlidd committed Jun 26, 2025
commit a26badd44a8bcde3aa0465dfa5bc8bf2a8d12820
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static datadog.trace.api.DDTags.DJM_ENABLED;
import static datadog.trace.api.DDTags.DSM_ENABLED;
import static datadog.trace.api.DDTags.PROFILING_CONTEXT_ENGINE;
import static datadog.trace.api.TracePropagationBehaviorExtract.RESTART;
import static datadog.trace.api.TracePropagationBehaviorExtract.IGNORE;
import static datadog.trace.bootstrap.instrumentation.api.AgentPropagation.BAGGAGE_CONCERN;
import static datadog.trace.bootstrap.instrumentation.api.AgentPropagation.DSM_CONCERN;
import static datadog.trace.bootstrap.instrumentation.api.AgentPropagation.TRACING_CONCERN;
Expand Down Expand Up @@ -716,7 +716,8 @@ private CoreTracer(
if (config.isDataStreamsEnabled()) {
Propagators.register(DSM_CONCERN, this.dataStreamsMonitoring.propagator());
}
if (config.isBaggagePropagationEnabled()) {
if (config.isBaggagePropagationEnabled()
&& config.getTracePropagationBehaviorExtract() != IGNORE) {
Propagators.register(BAGGAGE_CONCERN, new BaggagePropagator(config));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package datadog.trace.core.baggage;

import static datadog.trace.api.TracePropagationBehaviorExtract.IGNORE;
import static java.util.Collections.emptyMap;

import datadog.context.Context;
import datadog.context.propagation.CarrierSetter;
import datadog.context.propagation.CarrierVisitor;
import datadog.context.propagation.Propagator;
import datadog.trace.api.Config;
import datadog.trace.api.TracePropagationBehaviorExtract;
import datadog.trace.bootstrap.instrumentation.api.Baggage;
import datadog.trace.core.util.PercentEscaper;
import datadog.trace.core.util.PercentEscaper.Escaped;
Expand All @@ -30,29 +28,21 @@ public class BaggagePropagator implements Propagator {
private final boolean extractBaggage;
private final int maxItems;
private final int maxBytes;
private final TracePropagationBehaviorExtract behaviorExtract;

public BaggagePropagator(Config config) {
this(
config.isBaggageInject(),
config.isBaggageExtract(),
config.getTraceBaggageMaxItems(),
config.getTraceBaggageMaxBytes(),
config.getTracePropagationBehaviorExtract());
config.getTraceBaggageMaxBytes());
}

// use primarily for testing purposes
BaggagePropagator(
boolean injectBaggage,
boolean extractBaggage,
int maxItems,
int maxBytes,
TracePropagationBehaviorExtract behaviorExtract) {
BaggagePropagator(boolean injectBaggage, boolean extractBaggage, int maxItems, int maxBytes) {
this.injectBaggage = injectBaggage;
this.extractBaggage = extractBaggage;
this.maxItems = maxItems;
this.maxBytes = maxBytes;
this.behaviorExtract = behaviorExtract;
}

@Override
Expand Down Expand Up @@ -114,11 +104,7 @@ public <C> void inject(Context context, C carrier, CarrierSetter<C> setter) {

@Override
public <C> Context extract(Context context, C carrier, CarrierVisitor<C> visitor) {
if (!this.extractBaggage
|| this.behaviorExtract == IGNORE
|| context == null
|| carrier == null
|| visitor == null) {
if (!this.extractBaggage || context == null || carrier == null || visitor == null) {
return context;
}
BaggageExtractor baggageExtractor = new BaggageExtractor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import java.util.function.BiConsumer

import static datadog.trace.api.ConfigDefaults.DEFAULT_TRACE_BAGGAGE_MAX_BYTES
import static datadog.trace.api.ConfigDefaults.DEFAULT_TRACE_BAGGAGE_MAX_ITEMS
import static datadog.trace.api.TracePropagationBehaviorExtract.CONTINUE
import static datadog.trace.core.baggage.BaggagePropagator.BAGGAGE_KEY

class BaggagePropagatorTest extends DDSpecification {
Expand All @@ -36,7 +35,7 @@ class BaggagePropagatorTest extends DDSpecification {
}

def setup() {
this.propagator = new BaggagePropagator(true, true, DEFAULT_TRACE_BAGGAGE_MAX_ITEMS, DEFAULT_TRACE_BAGGAGE_MAX_BYTES, CONTINUE)
this.propagator = new BaggagePropagator(true, true, DEFAULT_TRACE_BAGGAGE_MAX_ITEMS, DEFAULT_TRACE_BAGGAGE_MAX_BYTES)
this.setter = new MapCarrierAccessor()
this.carrier = [:]
this.context = Context.root()
Expand Down Expand Up @@ -66,7 +65,7 @@ class BaggagePropagatorTest extends DDSpecification {

def "test baggage inject item limit"() {
setup:
propagator = new BaggagePropagator(true, true, 2, DEFAULT_TRACE_BAGGAGE_MAX_BYTES, CONTINUE) //creating a new instance after injecting config
propagator = new BaggagePropagator(true, true, 2, DEFAULT_TRACE_BAGGAGE_MAX_BYTES) //creating a new instance after injecting config
context = Baggage.create(baggage).storeInto(context)

when:
Expand All @@ -83,7 +82,7 @@ class BaggagePropagatorTest extends DDSpecification {

def "test baggage inject bytes limit"() {
setup:
propagator = new BaggagePropagator(true, true, DEFAULT_TRACE_BAGGAGE_MAX_ITEMS, 20, CONTINUE) //creating a new instance after injecting config
propagator = new BaggagePropagator(true, true, DEFAULT_TRACE_BAGGAGE_MAX_ITEMS, 20) //creating a new instance after injecting config
context = Baggage.create(baggage).storeInto(context)

when:
Expand Down Expand Up @@ -185,7 +184,7 @@ class BaggagePropagatorTest extends DDSpecification {

def "test baggage cache items limit"(){
setup:
propagator = new BaggagePropagator(true, true, 2, DEFAULT_TRACE_BAGGAGE_MAX_BYTES, CONTINUE) //creating a new instance after injecting config
propagator = new BaggagePropagator(true, true, 2, DEFAULT_TRACE_BAGGAGE_MAX_BYTES) //creating a new instance after injecting config
def headers = [
(BAGGAGE_KEY) : baggageHeader,
]
Expand All @@ -206,7 +205,7 @@ class BaggagePropagatorTest extends DDSpecification {

def "test baggage cache bytes limit"(){
setup:
propagator = new BaggagePropagator(true, true, DEFAULT_TRACE_BAGGAGE_MAX_ITEMS, 20, CONTINUE) //creating a new instance after injecting config
propagator = new BaggagePropagator(true, true, DEFAULT_TRACE_BAGGAGE_MAX_ITEMS, 20) //creating a new instance after injecting config
def headers = [
(BAGGAGE_KEY) : baggageHeader,
]
Expand Down