Allow tracing be disabled via config
MODIFY
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/AgentInstaller.java
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/AgentInstaller.java
@@ -43,8 +43,10 @@ public class AgentInstaller {
return INSTRUMENTATION;
}
- public static ResettableClassFileTransformer installBytebuddyAgent(final Instrumentation inst) {
- return installBytebuddyAgent(inst, new AgentBuilder.Listener[0]);
+ public static void installBytebuddyAgent(final Instrumentation inst) {
+ if (Config.get().isTraceEnabled()) {
+ installBytebuddyAgent(inst, new AgentBuilder.Listener[0]);
+ }
}
/**

MODIFY
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/TracerInstaller.java
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/TracerInstaller.java
package datadog.trace.agent.tooling;
import datadog.opentracing.DDTracer;
+import datadog.trace.api.Config;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class TracerInstaller {
/** Register a global tracer if no global tracer is already registered. */
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();
try {
io.opentracing.util.GlobalTracer.register(tracer);

MODIFY
dd-trace-api/src/main/java/datadog/trace/api/Config.java
dd-trace-api/src/main/java/datadog/trace/api/Config.java
@@ -35,6 +35,7 @@ public class Config {
public static final String SERVICE_NAME = "service.name";
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 AGENT_HOST = "agent.host";
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_STATSD_HOST = "jmxfetch.statsd.host";
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 LANGUAGE_TAG_KEY = "language";
public static final String LANGUAGE_TAG_VALUE = "jvm";
+
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 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 int DEFAULT_TRACE_AGENT_PORT = 8126;
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_PRIORITY_SAMPLING_ENABLED = true;
@@ -99,6 +100,7 @@ public class Config {
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 String SPLIT_BY_SPACE_OR_COMMA_REGEX = "[,\\s]+";
@@ -115,6 +117,7 @@ public class Config {
@Getter private final String runtimeId;
@Getter private final String serviceName;
+ @Getter private final boolean traceEnabled;
@Getter private final String writerType;
@Getter private final String agentHost;
@Getter private final int agentPort;
@@ -149,6 +152,8 @@ public class Config {
runtimeId = UUID.randomUUID().toString();
serviceName = getSettingFromEnvironment(SERVICE_NAME, DEFAULT_SERVICE_NAME);
+
+ traceEnabled = getBooleanSettingFromEnvironment(TRACE_ENABLED, DEFAULT_TRACE_ENABLED);
writerType = getSettingFromEnvironment(WRITER_TYPE, DEFAULT_AGENT_WRITER_TYPE);
agentHost = getSettingFromEnvironment(AGENT_HOST, DEFAULT_AGENT_HOST);
agentPort =
@@ -166,6 +171,7 @@ public class Config {
globalTags = getMapSettingFromEnvironment(GLOBAL_TAGS, null);
spanTags = getMapSettingFromEnvironment(SPAN_TAGS, null);
jmxTags = getMapSettingFromEnvironment(JMX_TAGS, null);
+
excludedClasses = getListSettingFromEnvironment(TRACE_CLASSES_EXCLUDE, null);
headerTags = getMapSettingFromEnvironment(HEADER_TAGS, null);
@@ -225,6 +231,8 @@ public class Config {
runtimeId = parent.runtimeId;
serviceName = properties.getProperty(SERVICE_NAME, parent.serviceName);
+
+ traceEnabled = getPropertyBooleanValue(properties, TRACE_ENABLED, parent.traceEnabled);
writerType = properties.getProperty(WRITER_TYPE, parent.writerType);
agentHost = properties.getProperty(AGENT_HOST, parent.agentHost);
agentPort =

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

Allow tracing be disabled via config