Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support DD_TRACE_<INTEGRATION>_ENABLED #7718

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -286,9 +286,35 @@ public boolean isIntegrationsEnabled() {
return integrationsEnabled;
}

/**
* isIntegrationEnabled determines whether an integration under the specified name(s) is enabled
* according to the following list of configurations, from highest to lowest precedence:
* trace.name.enabled, trace.integration.name.enabled, integration.name.enabled. If none of these
* configurations is set, the defaultEnabled value is used. All system properties take precedence
* over all env vars.
*
* @param integrationNames the name(s) that represent(s) the integration
* @param defaultEnabled true if enabled by default, else false
* @return boolean on whether the integration is enabled
*/
public boolean isIntegrationEnabled(
final Iterable<String> integrationNames, final boolean defaultEnabled) {
return configProvider.isEnabled(integrationNames, "integration.", ".enabled", defaultEnabled);
// If default is enabled, we want to disable individually.
// If default is disabled, we want to enable individually.
boolean anyEnabled = defaultEnabled;
for (final String name : integrationNames) {
final String primaryKey = "trace." + name + ".enabled";
final String[] aliases = {
"trace.integration." + name + ".enabled", "integration." + name + ".enabled"
}; // listed in order of precedence
final boolean configEnabled = configProvider.getBoolean(primaryKey, defaultEnabled, aliases);
if (defaultEnabled) {
anyEnabled &= configEnabled;
} else {
anyEnabled |= configEnabled;
}
}
return anyEnabled;
}

public boolean isIntegrationShortcutMatchingEnabled(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class InstrumenterConfigTest extends DDSpecification {
setup:
environmentVariables.set("DD_INTEGRATION_ORDER_ENABLED", "false")
environmentVariables.set("DD_INTEGRATION_TEST_ENV_ENABLED", "true")
environmentVariables.set("DD_TRACE_NEW_ENV_ENABLED", "false")
environmentVariables.set("DD_INTEGRATION_DISABLED_ENV_ENABLED", "false")

System.setProperty("dd.integration.order.enabled", "true")
Expand All @@ -16,6 +17,7 @@ class InstrumenterConfigTest extends DDSpecification {

environmentVariables.set("DD_INTEGRATION_ORDER_MATCHING_SHORTCUT_ENABLED", "false")
environmentVariables.set("DD_INTEGRATION_TEST_ENV_MATCHING_SHORTCUT_ENABLED", "true")
environmentVariables.set("DD_INTEGRATION_NEW_ENV_MATCHING_SHORTCUT_ENABLED", "false")
environmentVariables.set("DD_INTEGRATION_DISABLED_ENV_MATCHING_SHORTCUT_ENABLED", "false")

System.setProperty("dd.integration.order.matching.shortcut.enabled", "true")
Expand Down Expand Up @@ -44,11 +46,72 @@ class InstrumenterConfigTest extends DDSpecification {
["disabled-env", "test-env"] | false | true
["test-prop", "disabled-prop"] | true | false
["disabled-env", "test-env"] | true | false
["new-env"] | true | false
// spotless:on

integrationNames = new TreeSet<>(names)
}

def setEnv(String key, String value) {
environmentVariables.set(key, value)
}

def setSysProp(String key, String value) {
System.setProperty(key, value)
}

def randomIntegrationEnabled() {
return InstrumenterConfig.get().isIntegrationEnabled(["random"], true)
}

def "verify integration enabled hierarchy"() {
when:
// the below should have no effect
setEnv("DD_RANDOM_ENABLED", "false")
setSysProp("dd.random.enabled", "false")

then:
randomIntegrationEnabled() == true

when:
setEnv("DD_INTEGRATION_RANDOM_ENABLED", "false")

then:
randomIntegrationEnabled() == false

when:
setEnv("DD_TRACE_INTEGRATION_RANDOM_ENABLED", "true")

then:
randomIntegrationEnabled() == true

when:
setEnv("DD_TRACE_RANDOM_ENABLED", "false")

then:
randomIntegrationEnabled() == false

// assert all system properties take precedence over all env vars
when:
setSysProp("dd.integration.random.enabled", "true")

then:
randomIntegrationEnabled() == true

when:
setSysProp("dd.trace.integration.random.enabled", "false")

then:
randomIntegrationEnabled() == false

when:
setSysProp("dd.trace.random.enabled", "true")

then:
randomIntegrationEnabled() == true

}

def "valid resolver presets"() {
setup:
injectSysConfig("resolver.cache.config", preset)
Expand Down
Loading