Merge pull request #824 from DataDog/mar-kolya/allow-tracing-agent-to-be-disabled

Update to latest versions of groovy and spock
This commit is contained in:
Nikolay Martynov 2019-05-09 10:49:07 -04:00 committed by GitHub
commit e4416464cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 13 deletions

View File

@ -43,8 +43,10 @@ public class AgentInstaller {
return INSTRUMENTATION; return INSTRUMENTATION;
} }
public static ResettableClassFileTransformer installBytebuddyAgent(final Instrumentation inst) { public static void installBytebuddyAgent(final Instrumentation inst) {
return installBytebuddyAgent(inst, new AgentBuilder.Listener[0]); if (Config.get().isTraceEnabled()) {
installBytebuddyAgent(inst, new AgentBuilder.Listener[0]);
}
} }
/** /**

View File

@ -1,13 +1,14 @@
package datadog.trace.agent.tooling; package datadog.trace.agent.tooling;
import datadog.opentracing.DDTracer; import datadog.opentracing.DDTracer;
import datadog.trace.api.Config;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
public class TracerInstaller { public class TracerInstaller {
/** Register a global tracer if no global tracer is already registered. */ /** Register a global tracer if no global tracer is already registered. */
public static synchronized void installGlobalTracer() { public static synchronized void installGlobalTracer() {
if (!io.opentracing.util.GlobalTracer.isRegistered()) { if (Config.get().isTraceEnabled() && !io.opentracing.util.GlobalTracer.isRegistered()) {
final DDTracer tracer = new DDTracer(); final DDTracer tracer = new DDTracer();
try { try {
io.opentracing.util.GlobalTracer.register(tracer); io.opentracing.util.GlobalTracer.register(tracer);

View File

@ -32,5 +32,6 @@ dependencies {
} }
testCompile group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.0.0' testCompile group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.0.0'
latestDepTestCompile group: 'com.squareup.okhttp3', name: 'okhttp', version: '[3.11.0,)' // 4.x.x-alpha has been released and it looks like there are lots of incompatible changes
latestDepTestCompile group: 'com.squareup.okhttp3', name: 'okhttp', version: '[3.11.0, 4.0.0*)'
} }

View File

@ -35,6 +35,7 @@ public class Config {
public static final String SERVICE_NAME = "service.name"; public static final String SERVICE_NAME = "service.name";
public static final String SERVICE = "service"; public static final String SERVICE = "service";
public static final String TRACE_ENABLED = "trace.enabled";
public static final String WRITER_TYPE = "writer.type"; public static final String WRITER_TYPE = "writer.type";
public static final String AGENT_HOST = "agent.host"; public static final String AGENT_HOST = "agent.host";
public static final String TRACE_AGENT_PORT = "trace.agent.port"; public static final String TRACE_AGENT_PORT = "trace.agent.port";
@ -65,24 +66,24 @@ public class Config {
public static final String JMX_FETCH_REFRESH_BEANS_PERIOD = "jmxfetch.refresh-beans-period"; public static final String JMX_FETCH_REFRESH_BEANS_PERIOD = "jmxfetch.refresh-beans-period";
public static final String JMX_FETCH_STATSD_HOST = "jmxfetch.statsd.host"; public static final String JMX_FETCH_STATSD_HOST = "jmxfetch.statsd.host";
public static final String JMX_FETCH_STATSD_PORT = "jmxfetch.statsd.port"; public static final String JMX_FETCH_STATSD_PORT = "jmxfetch.statsd.port";
public static final String APP_CUSTOM_LOG_MANAGER = "app.customlogmanager"; public static final String LOGS_INJECTION_ENABLED = "logs.injection";
private static final String APP_CUSTOM_LOG_MANAGER = "app.customlogmanager";
public static final String RUNTIME_ID_TAG = "runtime-id"; public static final String RUNTIME_ID_TAG = "runtime-id";
public static final String LANGUAGE_TAG_KEY = "language"; public static final String LANGUAGE_TAG_KEY = "language";
public static final String LANGUAGE_TAG_VALUE = "jvm"; public static final String LANGUAGE_TAG_VALUE = "jvm";
public static final String DEFAULT_SERVICE_NAME = "unnamed-java-app"; public static final String DEFAULT_SERVICE_NAME = "unnamed-java-app";
private static final boolean DEFAULT_TRACE_ENABLED = true;
public static final String DD_AGENT_WRITER_TYPE = "DDAgentWriter"; public static final String DD_AGENT_WRITER_TYPE = "DDAgentWriter";
public static final String LOGGING_WRITER_TYPE = "LoggingWriter"; public static final String LOGGING_WRITER_TYPE = "LoggingWriter";
public static final String DEFAULT_AGENT_WRITER_TYPE = DD_AGENT_WRITER_TYPE; private static final String DEFAULT_AGENT_WRITER_TYPE = DD_AGENT_WRITER_TYPE;
public static final String DEFAULT_AGENT_HOST = "localhost"; public static final String DEFAULT_AGENT_HOST = "localhost";
public static final int DEFAULT_TRACE_AGENT_PORT = 8126; public static final int DEFAULT_TRACE_AGENT_PORT = 8126;
public static final String DEFAULT_AGENT_UNIX_DOMAIN_SOCKET = null; public static final String DEFAULT_AGENT_UNIX_DOMAIN_SOCKET = null;
public static final String LOGS_INJECTION_ENABLED = "logs.injection";
public static final boolean DEFAULT_LOGS_INJECTION_ENABLED = false;
private static final boolean DEFAULT_RUNTIME_CONTEXT_FIELD_INJECTION = true; private static final boolean DEFAULT_RUNTIME_CONTEXT_FIELD_INJECTION = true;
private static final boolean DEFAULT_PRIORITY_SAMPLING_ENABLED = true; private static final boolean DEFAULT_PRIORITY_SAMPLING_ENABLED = true;
@ -99,6 +100,7 @@ public class Config {
public static final int DEFAULT_JMX_FETCH_STATSD_PORT = 8125; public static final int DEFAULT_JMX_FETCH_STATSD_PORT = 8125;
public static final boolean DEFAULT_LOGS_INJECTION_ENABLED = false;
private static final boolean DEFAULT_APP_CUSTOM_LOG_MANAGER = false; private static final boolean DEFAULT_APP_CUSTOM_LOG_MANAGER = false;
private static final String SPLIT_BY_SPACE_OR_COMMA_REGEX = "[,\\s]+"; private static final String SPLIT_BY_SPACE_OR_COMMA_REGEX = "[,\\s]+";
@ -115,6 +117,7 @@ public class Config {
@Getter private final String runtimeId; @Getter private final String runtimeId;
@Getter private final String serviceName; @Getter private final String serviceName;
@Getter private final boolean traceEnabled;
@Getter private final String writerType; @Getter private final String writerType;
@Getter private final String agentHost; @Getter private final String agentHost;
@Getter private final int agentPort; @Getter private final int agentPort;
@ -149,6 +152,8 @@ public class Config {
runtimeId = UUID.randomUUID().toString(); runtimeId = UUID.randomUUID().toString();
serviceName = getSettingFromEnvironment(SERVICE_NAME, DEFAULT_SERVICE_NAME); serviceName = getSettingFromEnvironment(SERVICE_NAME, DEFAULT_SERVICE_NAME);
traceEnabled = getBooleanSettingFromEnvironment(TRACE_ENABLED, DEFAULT_TRACE_ENABLED);
writerType = getSettingFromEnvironment(WRITER_TYPE, DEFAULT_AGENT_WRITER_TYPE); writerType = getSettingFromEnvironment(WRITER_TYPE, DEFAULT_AGENT_WRITER_TYPE);
agentHost = getSettingFromEnvironment(AGENT_HOST, DEFAULT_AGENT_HOST); agentHost = getSettingFromEnvironment(AGENT_HOST, DEFAULT_AGENT_HOST);
agentPort = agentPort =
@ -166,6 +171,7 @@ public class Config {
globalTags = getMapSettingFromEnvironment(GLOBAL_TAGS, null); globalTags = getMapSettingFromEnvironment(GLOBAL_TAGS, null);
spanTags = getMapSettingFromEnvironment(SPAN_TAGS, null); spanTags = getMapSettingFromEnvironment(SPAN_TAGS, null);
jmxTags = getMapSettingFromEnvironment(JMX_TAGS, null); jmxTags = getMapSettingFromEnvironment(JMX_TAGS, null);
excludedClasses = getListSettingFromEnvironment(TRACE_CLASSES_EXCLUDE, null); excludedClasses = getListSettingFromEnvironment(TRACE_CLASSES_EXCLUDE, null);
headerTags = getMapSettingFromEnvironment(HEADER_TAGS, null); headerTags = getMapSettingFromEnvironment(HEADER_TAGS, null);
@ -225,6 +231,8 @@ public class Config {
runtimeId = parent.runtimeId; runtimeId = parent.runtimeId;
serviceName = properties.getProperty(SERVICE_NAME, parent.serviceName); serviceName = properties.getProperty(SERVICE_NAME, parent.serviceName);
traceEnabled = getPropertyBooleanValue(properties, TRACE_ENABLED, parent.traceEnabled);
writerType = properties.getProperty(WRITER_TYPE, parent.writerType); writerType = properties.getProperty(WRITER_TYPE, parent.writerType);
agentHost = properties.getProperty(AGENT_HOST, parent.agentHost); agentHost = properties.getProperty(AGENT_HOST, parent.agentHost);
agentPort = agentPort =

View File

@ -35,6 +35,7 @@ import static datadog.trace.api.Config.SERVICE_MAPPING
import static datadog.trace.api.Config.SERVICE_NAME import static datadog.trace.api.Config.SERVICE_NAME
import static datadog.trace.api.Config.SPAN_TAGS import static datadog.trace.api.Config.SPAN_TAGS
import static datadog.trace.api.Config.TRACE_AGENT_PORT import static datadog.trace.api.Config.TRACE_AGENT_PORT
import static datadog.trace.api.Config.TRACE_ENABLED
import static datadog.trace.api.Config.TRACE_RESOLVER_ENABLED import static datadog.trace.api.Config.TRACE_RESOLVER_ENABLED
import static datadog.trace.api.Config.WRITER_TYPE import static datadog.trace.api.Config.WRITER_TYPE
@ -45,6 +46,7 @@ class ConfigTest extends Specification {
public final EnvironmentVariables environmentVariables = new EnvironmentVariables() public final EnvironmentVariables environmentVariables = new EnvironmentVariables()
private static final DD_SERVICE_NAME_ENV = "DD_SERVICE_NAME" private static final DD_SERVICE_NAME_ENV = "DD_SERVICE_NAME"
private static final DD_TRACE_ENABLED_ENV = "DD_TRACE_ENABLED"
private static final DD_WRITER_TYPE_ENV = "DD_WRITER_TYPE" private static final DD_WRITER_TYPE_ENV = "DD_WRITER_TYPE"
private static final DD_SERVICE_MAPPING_ENV = "DD_SERVICE_MAPPING" private static final DD_SERVICE_MAPPING_ENV = "DD_SERVICE_MAPPING"
private static final DD_SPAN_TAGS_ENV = "DD_SPAN_TAGS" private static final DD_SPAN_TAGS_ENV = "DD_SPAN_TAGS"
@ -61,6 +63,7 @@ class ConfigTest extends Specification {
then: then:
config.serviceName == "unnamed-java-app" config.serviceName == "unnamed-java-app"
config.traceEnabled == true
config.writerType == "DDAgentWriter" config.writerType == "DDAgentWriter"
config.agentHost == "localhost" config.agentHost == "localhost"
config.agentPort == 8126 config.agentPort == 8126
@ -98,6 +101,7 @@ class ConfigTest extends Specification {
setup: setup:
def prop = new Properties() def prop = new Properties()
prop.setProperty(SERVICE_NAME, "something else") prop.setProperty(SERVICE_NAME, "something else")
prop.setProperty(TRACE_ENABLED, "false")
prop.setProperty(WRITER_TYPE, "LoggingWriter") prop.setProperty(WRITER_TYPE, "LoggingWriter")
prop.setProperty(AGENT_HOST, "somehost") prop.setProperty(AGENT_HOST, "somehost")
prop.setProperty(TRACE_AGENT_PORT, "123") prop.setProperty(TRACE_AGENT_PORT, "123")
@ -129,6 +133,7 @@ class ConfigTest extends Specification {
then: then:
config.serviceName == "something else" config.serviceName == "something else"
config.traceEnabled == false
config.writerType == "LoggingWriter" config.writerType == "LoggingWriter"
config.agentHost == "somehost" config.agentHost == "somehost"
config.agentPort == 123 config.agentPort == 123
@ -157,6 +162,7 @@ class ConfigTest extends Specification {
def "specify overrides via system properties"() { def "specify overrides via system properties"() {
setup: setup:
System.setProperty(PREFIX + SERVICE_NAME, "something else") System.setProperty(PREFIX + SERVICE_NAME, "something else")
System.setProperty(PREFIX + TRACE_ENABLED, "false")
System.setProperty(PREFIX + WRITER_TYPE, "LoggingWriter") System.setProperty(PREFIX + WRITER_TYPE, "LoggingWriter")
System.setProperty(PREFIX + AGENT_HOST, "somehost") System.setProperty(PREFIX + AGENT_HOST, "somehost")
System.setProperty(PREFIX + TRACE_AGENT_PORT, "123") System.setProperty(PREFIX + TRACE_AGENT_PORT, "123")
@ -188,6 +194,7 @@ class ConfigTest extends Specification {
then: then:
config.serviceName == "something else" config.serviceName == "something else"
config.traceEnabled == false
config.writerType == "LoggingWriter" config.writerType == "LoggingWriter"
config.agentHost == "somehost" config.agentHost == "somehost"
config.agentPort == 123 config.agentPort == 123
@ -216,6 +223,7 @@ class ConfigTest extends Specification {
def "specify overrides via env vars"() { def "specify overrides via env vars"() {
setup: setup:
environmentVariables.set(DD_SERVICE_NAME_ENV, "still something else") environmentVariables.set(DD_SERVICE_NAME_ENV, "still something else")
environmentVariables.set(DD_TRACE_ENABLED_ENV, "false")
environmentVariables.set(DD_WRITER_TYPE_ENV, "LoggingWriter") environmentVariables.set(DD_WRITER_TYPE_ENV, "LoggingWriter")
environmentVariables.set(DD_PROPAGATION_STYLE_EXTRACT, "B3 Datadog") environmentVariables.set(DD_PROPAGATION_STYLE_EXTRACT, "B3 Datadog")
environmentVariables.set(DD_PROPAGATION_STYLE_INJECT, "Datadog B3") environmentVariables.set(DD_PROPAGATION_STYLE_INJECT, "Datadog B3")
@ -226,6 +234,7 @@ class ConfigTest extends Specification {
then: then:
config.serviceName == "still something else" config.serviceName == "still something else"
config.traceEnabled == false
config.writerType == "LoggingWriter" config.writerType == "LoggingWriter"
config.propagationStylesToExtract.toList() == [Config.PropagationStyle.B3, Config.PropagationStyle.DATADOG] config.propagationStylesToExtract.toList() == [Config.PropagationStyle.B3, Config.PropagationStyle.DATADOG]
config.propagationStylesToInject.toList() == [Config.PropagationStyle.DATADOG, Config.PropagationStyle.B3] config.propagationStylesToInject.toList() == [Config.PropagationStyle.DATADOG, Config.PropagationStyle.B3]
@ -256,6 +265,7 @@ class ConfigTest extends Specification {
def "default when configured incorrectly"() { def "default when configured incorrectly"() {
setup: setup:
System.setProperty(PREFIX + SERVICE_NAME, " ") System.setProperty(PREFIX + SERVICE_NAME, " ")
System.setProperty(PREFIX + TRACE_ENABLED, " ")
System.setProperty(PREFIX + WRITER_TYPE, " ") System.setProperty(PREFIX + WRITER_TYPE, " ")
System.setProperty(PREFIX + AGENT_HOST, " ") System.setProperty(PREFIX + AGENT_HOST, " ")
System.setProperty(PREFIX + TRACE_AGENT_PORT, " ") System.setProperty(PREFIX + TRACE_AGENT_PORT, " ")
@ -276,6 +286,7 @@ class ConfigTest extends Specification {
then: then:
config.serviceName == " " config.serviceName == " "
config.traceEnabled == true
config.writerType == " " config.writerType == " "
config.agentHost == " " config.agentHost == " "
config.agentPort == 8126 config.agentPort == 8126
@ -337,6 +348,7 @@ class ConfigTest extends Specification {
setup: setup:
Properties properties = new Properties() Properties properties = new Properties()
properties.setProperty(SERVICE_NAME, "something else") properties.setProperty(SERVICE_NAME, "something else")
properties.setProperty(TRACE_ENABLED, "false")
properties.setProperty(WRITER_TYPE, "LoggingWriter") properties.setProperty(WRITER_TYPE, "LoggingWriter")
properties.setProperty(AGENT_HOST, "somehost") properties.setProperty(AGENT_HOST, "somehost")
properties.setProperty(TRACE_AGENT_PORT, "123") properties.setProperty(TRACE_AGENT_PORT, "123")
@ -365,6 +377,7 @@ class ConfigTest extends Specification {
then: then:
config.serviceName == "something else" config.serviceName == "something else"
config.traceEnabled == false
config.writerType == "LoggingWriter" config.writerType == "LoggingWriter"
config.agentHost == "somehost" config.agentHost == "somehost"
config.agentPort == 123 config.agentPort == 123

View File

@ -1,4 +1,4 @@
def groovyVer = "2.5.3" def groovyVer = "2.5.6"
def spockGroovyVer = groovyVer.replaceAll(/\.\d+$/, '') def spockGroovyVer = groovyVer.replaceAll(/\.\d+$/, '')
ext { ext {
@ -9,7 +9,7 @@ ext {
guava : "20.0", // Last version to support Java 7 guava : "20.0", // Last version to support Java 7
jackson : "2.9.8", // https://nvd.nist.gov/vuln/detail/CVE-2018-1000873 jackson : "2.9.8", // https://nvd.nist.gov/vuln/detail/CVE-2018-1000873
spock : "1.2-groovy-$spockGroovyVer", spock : "1.3-groovy-$spockGroovyVer",
groovy : groovyVer, groovy : groovyVer,
junit : "4.12", junit : "4.12",
logback : "1.2.3", logback : "1.2.3",