Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .circleci/config.continue.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ instrumentation_modules: &instrumentation_modules "dd-java-agent/instrumentation
debugger_modules: &debugger_modules "dd-java-agent/agent-debugger|dd-java-agent/agent-bootstrap|dd-java-agent/agent-builder|internal-api|communication|dd-trace-core"
profiling_modules: &profiling_modules "dd-java-agent/agent-profiling"

default_system_tests_commit: &default_system_tests_commit 2374d120bbbc94109c449a0a9c182a9d4d0af60e
default_system_tests_commit: &default_system_tests_commit 899511453a9beb4dd560eb45ec45a8328383c80a
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Point to this fix for the test_app_started_client_configuration system test cherry-picked on top of 2374d120bbbc94109c449a0a9c182a9d4d0af60e


parameters:
nightly:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public final class GeneralConfig {
public static final String ENV = "env";
public static final String VERSION = "version";
public static final String PRIMARY_TAG = "primary.tag";
public static final String TRACE_TAGS = "trace.tags";
public static final String TAGS = "tags";
@Deprecated // Use dd.tags instead
public static final String GLOBAL_TAGS = "trace.global.tags";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ public final class TraceInstrumentationConfig {
public static final String SERIALVERSIONUID_FIELD_INJECTION =
"trace.serialversionuid.field.injection";

public static final String LOGS_INJECTION_ENABLED = "logs.injection";
public static final String LOGS_INJECTION_ENABLED = "logs.injection.enabled";
public static final String LOGS_INJECTION = "logs.injection";

public static final String TRACE_128_BIT_TRACEID_LOGGING_ENABLED =
"trace.128.bit.traceid.logging.enabled";

Expand Down
7 changes: 5 additions & 2 deletions internal-api/src/main/java/datadog/trace/api/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
import static datadog.trace.api.config.GeneralConfig.TRACER_METRICS_MAX_AGGREGATES;
import static datadog.trace.api.config.GeneralConfig.TRACER_METRICS_MAX_PENDING;
import static datadog.trace.api.config.GeneralConfig.TRACE_DEBUG;
import static datadog.trace.api.config.GeneralConfig.TRACE_TAGS;
import static datadog.trace.api.config.GeneralConfig.TRACE_TRIAGE;
import static datadog.trace.api.config.GeneralConfig.TRIAGE_REPORT_DIR;
import static datadog.trace.api.config.GeneralConfig.TRIAGE_REPORT_TRIGGER;
Expand Down Expand Up @@ -363,6 +364,7 @@
import static datadog.trace.api.config.TraceInstrumentationConfig.JMS_UNACKNOWLEDGED_MAX_AGE;
import static datadog.trace.api.config.TraceInstrumentationConfig.KAFKA_CLIENT_BASE64_DECODING_ENABLED;
import static datadog.trace.api.config.TraceInstrumentationConfig.KAFKA_CLIENT_PROPAGATION_DISABLED_TOPICS;
import static datadog.trace.api.config.TraceInstrumentationConfig.LOGS_INJECTION;
import static datadog.trace.api.config.TraceInstrumentationConfig.LOGS_INJECTION_ENABLED;
import static datadog.trace.api.config.TraceInstrumentationConfig.MESSAGE_BROKER_SPLIT_BY_DESTINATION;
import static datadog.trace.api.config.TraceInstrumentationConfig.OBFUSCATION_QUERY_STRING_REGEXP;
Expand Down Expand Up @@ -1106,7 +1108,7 @@ private Config(final ConfigProvider configProvider, final InstrumenterConfig ins

{
final Map<String, String> tags = new HashMap<>(configProvider.getMergedMap(GLOBAL_TAGS));
tags.putAll(configProvider.getMergedMap(TAGS));
tags.putAll(configProvider.getMergedMap(TRACE_TAGS, TAGS));
this.tags = getMapWithPropertiesDefinedByEnvironment(tags, ENV, VERSION);
}

Expand Down Expand Up @@ -1330,7 +1332,8 @@ private Config(final ConfigProvider configProvider, final InstrumenterConfig ins
clockSyncPeriod = configProvider.getInteger(CLOCK_SYNC_PERIOD, DEFAULT_CLOCK_SYNC_PERIOD);

logsInjectionEnabled =
configProvider.getBoolean(LOGS_INJECTION_ENABLED, DEFAULT_LOGS_INJECTION_ENABLED);
configProvider.getBoolean(
LOGS_INJECTION_ENABLED, DEFAULT_LOGS_INJECTION_ENABLED, LOGS_INJECTION);

dogStatsDNamedPipe = configProvider.getString(DOGSTATSD_NAMED_PIPE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static ConfigCollector get() {
}

public void put(String key, Object value, ConfigOrigin origin) {
ConfigSetting setting = new ConfigSetting(key, value, origin);
ConfigSetting setting = ConfigSetting.of(key, value, origin);
collected.put(key, setting);
}

Expand All @@ -32,7 +32,7 @@ public void putAll(Map<String, Object> keysAndValues, ConfigOrigin origin) {
Map<String, ConfigSetting> merged =
new ConcurrentHashMap<>(keysAndValues.size() + collected.size());
for (Map.Entry<String, Object> entry : keysAndValues.entrySet()) {
ConfigSetting setting = new ConfigSetting(entry.getKey(), entry.getValue(), origin);
ConfigSetting setting = ConfigSetting.of(entry.getKey(), entry.getValue(), origin);
merged.put(entry.getKey(), setting);
}
while (true) {
Expand Down
82 changes: 76 additions & 6 deletions internal-api/src/main/java/datadog/trace/api/ConfigSetting.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package datadog.trace.api;

import java.util.Arrays;
import java.util.BitSet;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

Expand All @@ -14,16 +16,84 @@ public final class ConfigSetting {
new HashSet<>(
Arrays.asList("DD_API_KEY", "dd.api-key", "dd.profiling.api-key", "dd.profiling.apikey"));

private static Object filterConfigEntry(String key, Object value) {
return CONFIG_FILTER_LIST.contains(key) ? "<hidden>" : value;
public static ConfigSetting of(String key, Object value, ConfigOrigin origin) {
return new ConfigSetting(key, value, origin);
}

public ConfigSetting(String key, Object value, ConfigOrigin origin) {
private ConfigSetting(String key, Object value, ConfigOrigin origin) {
this.key = key;
this.value = filterConfigEntry(key, value);
this.value = CONFIG_FILTER_LIST.contains(key) ? "<hidden>" : value;
this.origin = origin;
}

public String normalizedKey() {
return key.toLowerCase().replace(".", "_");
}

public String stringValue() {
if (value == null) {
return null;
} else if (value instanceof BitSet) {
return renderIntegerRange((BitSet) value);
} else if (value instanceof Map) {
return renderMap((Map<Object, Object>) value);
} else if (value instanceof Iterable) {
return renderIterable((Iterable) value);
} else {
return value.toString();
}
}

private static String renderIntegerRange(BitSet bitset) {
StringBuilder sb = new StringBuilder();
int start = 0;
while (true) {
start = bitset.nextSetBit(start);
if (start < 0) {
break;
}
int end = bitset.nextClearBit(start);
if (sb.length() > 0) {
sb.append(',');
}
if (start < end - 1) {
// interval
sb.append(start);
sb.append('-');
sb.append(end);
} else {
// single value
sb.append(start);
}
start = end;
}
return sb.toString();
}

private static String renderMap(Map<Object, Object> merged) {
StringBuilder result = new StringBuilder();
for (Map.Entry entry : merged.entrySet()) {
if (result.length() > 0) {
result.append(',');
}
result.append(entry.getKey());
result.append(':');
result.append(entry.getValue());
}
return result.toString();
}

private static String renderIterable(Iterable iterable) {
StringBuilder result = new StringBuilder();
for (Object entry : iterable) {
if (result.length() > 0) {
result.append(',');
}
result.append(entry);
}
return result.toString();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand All @@ -41,10 +111,10 @@ public int hashCode() {
public String toString() {
return "ConfigSetting{"
+ "key='"
+ key
+ normalizedKey()
+ '\''
+ ", value="
+ value
+ stringValue()
+ ", origin="
+ origin
+ '}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,30 +363,4 @@ protected MethodHandle computeValue(Class<?> type) {
}
}
}

public static String renderIntegerRange(BitSet bitset) {
StringBuilder sb = new StringBuilder();
int start = 0;
while (true) {
start = bitset.nextSetBit(start);
if (start < 0) {
break;
}
int end = bitset.nextClearBit(start);
if (sb.length() > 0) {
sb.append(',');
}
if (start < end - 1) {
// interval
sb.append(start);
sb.append('-');
sb.append(end);
} else {
// single value
sb.append(start);
}
start = end;
}
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public <T extends Enum<T>> T getEnum(String key, Class<T> enumType, T defaultVal
}
}
if (collectConfig) {
ConfigCollector.get().put(key, String.valueOf(defaultValue), ConfigOrigin.DEFAULT);
String valueStr = defaultValue == null ? null : defaultValue.name();
ConfigCollector.get().put(key, valueStr, ConfigOrigin.DEFAULT);
}
return defaultValue;
}
Expand All @@ -81,7 +82,7 @@ public String getString(String key, String defaultValue, String... aliases) {
return value;
}
}
if (collectConfig && defaultValue != null) {
if (collectConfig) {
ConfigCollector.get().put(key, defaultValue, ConfigOrigin.DEFAULT);
}
return defaultValue;
Expand All @@ -101,7 +102,7 @@ public String getStringNotEmpty(String key, String defaultValue, String... alias
return value;
}
}
if (collectConfig && defaultValue != null) {
if (collectConfig) {
ConfigCollector.get().put(key, defaultValue, ConfigOrigin.DEFAULT);
}
return defaultValue;
Expand All @@ -125,7 +126,7 @@ public String getStringExcludingSource(
return value;
}
}
if (collectConfig && defaultValue != null) {
if (collectConfig) {
ConfigCollector.get().put(key, defaultValue, ConfigOrigin.DEFAULT);
}
return defaultValue;
Expand Down Expand Up @@ -203,7 +204,7 @@ private <T> T get(String key, T defaultValue, Class<T> type, String... aliases)
// continue
}
}
if (collectConfig && defaultValue != null) {
if (collectConfig) {
ConfigCollector.get().put(key, defaultValue, ConfigOrigin.DEFAULT);
}
return defaultValue;
Expand All @@ -216,8 +217,8 @@ public List<String> getList(String key) {
public List<String> getList(String key, List<String> defaultValue) {
String list = getString(key);
if (null == list) {
if (collectConfig && defaultValue != null) {
ConfigCollector.get().put(key, String.join(",", defaultValue), ConfigOrigin.DEFAULT);
if (collectConfig) {
ConfigCollector.get().put(key, defaultValue, ConfigOrigin.DEFAULT);
}
return defaultValue;
} else {
Expand All @@ -228,9 +229,8 @@ public List<String> getList(String key, List<String> defaultValue) {
public Set<String> getSet(String key, Set<String> defaultValue) {
String list = getString(key);
if (null == list) {
if (collectConfig && defaultValue != null) {
String defaultValueStr = String.join(",", defaultValue);
ConfigCollector.get().put(key, defaultValueStr, ConfigOrigin.DEFAULT);
if (collectConfig) {
ConfigCollector.get().put(key, defaultValue, ConfigOrigin.DEFAULT);
}
return defaultValue;
} else {
Expand All @@ -242,22 +242,24 @@ public List<String> getSpacedList(String key) {
return ConfigConverter.parseList(getString(key), " ");
}

public Map<String, String> getMergedMap(String key) {
public Map<String, String> getMergedMap(String key, String... aliases) {
Map<String, String> merged = new HashMap<>();
ConfigOrigin origin = ConfigOrigin.DEFAULT;
// System properties take precedence over env
// prior art:
// https://docs.spring.io/spring-boot/docs/1.5.6.RELEASE/reference/html/boot-features-external-config.html
// We reverse iterate to allow overrides
for (int i = sources.length - 1; 0 <= i; i--) {
String value = sources[i].get(key);
String value = sources[i].get(key, aliases);
Map<String, String> parsedMap = ConfigConverter.parseMap(value, key);
if (!parsedMap.isEmpty()) {
origin = sources[i].origin();
}
merged.putAll(parsedMap);
}
collectMapSetting(key, merged, origin);
if (collectConfig) {
ConfigCollector.get().put(key, merged, origin);
}
return merged;
}

Expand All @@ -276,7 +278,9 @@ public Map<String, String> getOrderedMap(String key) {
}
merged.putAll(parsedMap);
}
collectMapSetting(key, merged, origin);
if (collectConfig) {
ConfigCollector.get().put(key, merged, origin);
}
return merged;
}

Expand All @@ -298,7 +302,9 @@ public Map<String, String> getMergedMapWithOptionalMappings(
}
merged.putAll(parsedMap);
}
collectMapSetting(key, merged, origin);
if (collectConfig) {
ConfigCollector.get().put(key, merged, origin);
}
}
return merged;
}
Expand All @@ -313,8 +319,7 @@ public BitSet getIntegerRange(final String key, final BitSet defaultValue) {
log.warn("Invalid configuration for {}", key, e);
}
if (collectConfig) {
String defaultValueStr = ConfigConverter.renderIntegerRange(defaultValue);
ConfigCollector.get().put(key, defaultValueStr, ConfigOrigin.DEFAULT);
ConfigCollector.get().put(key, defaultValue, ConfigOrigin.DEFAULT);
}
return defaultValue;
}
Expand Down Expand Up @@ -407,22 +412,6 @@ public static ConfigProvider withPropertiesOverride(Properties properties) {
}
}

private void collectMapSetting(String key, Map<String, String> merged, ConfigOrigin origin) {
if (!collectConfig || merged.isEmpty()) {
return;
}
StringBuilder mergedValue = new StringBuilder();
for (Map.Entry<String, String> entry : merged.entrySet()) {
if (mergedValue.length() > 0) {
mergedValue.append(',');
}
mergedValue.append(entry.getKey());
mergedValue.append(':');
mergedValue.append(entry.getValue());
}
ConfigCollector.get().put(key, mergedValue.toString(), origin);
}

/**
* Loads the optional configuration properties file into the global {@link Properties} object.
*
Expand Down
Loading