Fix tests after changing config from static to instance access
MODIFY
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/decorator/BaseDecorator.java
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/decorator/BaseDecorator.java
@@ -23,17 +23,13 @@ public abstract class BaseDecorator {
protected final float traceAnalyticsSampleRate;
protected BaseDecorator() {
+ Config config = Config.get();
final String[] instrumentationNames = instrumentationNames();
traceAnalyticsEnabled =
instrumentationNames.length > 0
- && Config.get()
- .isTraceAnalyticsIntegrationEnabled(
+ && config.isTraceAnalyticsIntegrationEnabled(
new TreeSet<>(Arrays.asList(instrumentationNames)), traceAnalyticsDefault());
- float rate = 1.0f;
- for (final String name : instrumentationNames) {
- rate = Config.get().getInstrumentationAnalyticsSampleRate(name);
- }
- traceAnalyticsSampleRate = rate;
+ traceAnalyticsSampleRate = config.getInstrumentationAnalyticsSampleRate(instrumentationNames);
}
protected abstract String[] instrumentationNames();

MODIFY
dd-java-agent/agent-tooling/src/test/groovy/datadog/trace/agent/decorator/BaseDecoratorTest.groovy
dd-java-agent/agent-tooling/src/test/groovy/datadog/trace/agent/decorator/BaseDecoratorTest.groovy
@@ -172,6 +172,7 @@ class BaseDecoratorTest extends Specification {
when:
BaseDecorator dec = withSystemProperty("dd.${integName}.analytics.enabled", "true") {
withSystemProperty("dd.${integName}.analytics.sample-rate", "$sampleRate") {
+ ConfigUtils.resetConfig()
newDecorator(enabled)
}
}

MODIFY
dd-java-agent/agent-tooling/src/test/groovy/datadog/trace/agent/test/DefaultInstrumenterTest.groovy
dd-java-agent/agent-tooling/src/test/groovy/datadog/trace/agent/test/DefaultInstrumenterTest.groovy
@@ -81,6 +81,7 @@ class DefaultInstrumenterTest extends Specification {
def "configure default sys prop as #value"() {
setup:
System.setProperty("dd.integrations.enabled", value)
+ ConfigUtils.resetConfig()
def target = new TestDefaultInstrumenter("test")
target.instrument(new AgentBuilder.Default())
@@ -98,6 +99,7 @@ class DefaultInstrumenterTest extends Specification {
def "configure default env var as #value"() {
setup:
environmentVariables.set("DD_INTEGRATIONS_ENABLED", value)
+ ConfigUtils.resetConfig()
def target = new TestDefaultInstrumenter("test")
target.instrument(new AgentBuilder.Default())

MODIFY
dd-trace-api/src/main/java/datadog/trace/api/Config.java
dd-trace-api/src/main/java/datadog/trace/api/Config.java
@@ -439,9 +439,14 @@ public class Config {
* Returns the sample rate for the specified instrumentation or {@link
* #DEFAULT_ANALYTICS_SAMPLE_RATE} if none specified.
*/
- public float getInstrumentationAnalyticsSampleRate(String instrumentationName) {
- return getFloatSettingFromEnvironment(
- instrumentationName + ".analytics.sample-rate", DEFAULT_ANALYTICS_SAMPLE_RATE);
+ public float getInstrumentationAnalyticsSampleRate(String... aliases) {
+ for (final String alias : aliases) {
+ Float rate = getFloatSettingFromEnvironment(alias + ".analytics.sample-rate", null);
+ if (null != rate) {
+ return rate;
+ }
+ }
+ return DEFAULT_ANALYTICS_SAMPLE_RATE;
}
/**

Fix tests after changing config from static to instance access