disable hystrix tags by default, enabled by system property (DataDog/dd-trace-java#1743)

This commit is contained in:
Richard Startin 2020-08-04 16:31:45 +01:00 committed by Trask Stalnaker
parent 80ee4f1d7c
commit 278672595b
5 changed files with 42 additions and 3 deletions

View File

@ -84,6 +84,8 @@ public class Config {
public static final String KAFKA_CLIENT_PROPAGATION_ENABLED = "kafka.client.propagation.enabled";
public static final String HYSTRIX_TAGS_ENABLED = "hystrix.tags.enabled";
public static final String ENDPOINT_PEER_SERVICE_MAPPING = "endpoint.peer.service.mapping";
private static final boolean DEFAULT_TRACE_ENABLED = true;
@ -100,6 +102,8 @@ public class Config {
public static final boolean DEFAULT_KAFKA_CLIENT_PROPAGATION_ENABLED = true;
public static final boolean DEFAULT_HYSTRIX_TAGS_ENABLED = false;
private static final String DEFAULT_TRACE_ANNOTATIONS = null;
private static final boolean DEFAULT_TRACE_EXECUTORS_ALL = false;
private static final String DEFAULT_TRACE_EXECUTORS = "";
@ -132,6 +136,8 @@ public class Config {
private final boolean kafkaClientPropagationEnabled;
private final boolean hystrixTagsEnabled;
private final Map<String, String> endpointPeerServiceMapping;
// Values from an optionally provided properties file
@ -185,6 +191,9 @@ public class Config {
getBooleanSettingFromEnvironment(
KAFKA_CLIENT_PROPAGATION_ENABLED, DEFAULT_KAFKA_CLIENT_PROPAGATION_ENABLED);
hystrixTagsEnabled =
getBooleanSettingFromEnvironment(HYSTRIX_TAGS_ENABLED, DEFAULT_HYSTRIX_TAGS_ENABLED);
endpointPeerServiceMapping = getMapSettingFromEnvironment(ENDPOINT_PEER_SERVICE_MAPPING);
log.debug("New instance: {}", this);
@ -237,6 +246,9 @@ public class Config {
getPropertyBooleanValue(
properties, KAFKA_CLIENT_PROPAGATION_ENABLED, parent.kafkaClientPropagationEnabled);
hystrixTagsEnabled =
getBooleanSettingFromEnvironment(HYSTRIX_TAGS_ENABLED, parent.hystrixTagsEnabled);
endpointPeerServiceMapping =
getPropertyMapValue(
properties, ENDPOINT_PEER_SERVICE_MAPPING, parent.endpointPeerServiceMapping);
@ -567,6 +579,10 @@ public class Config {
return kafkaClientPropagationEnabled;
}
public boolean isHystrixTagsEnabled() {
return hystrixTagsEnabled;
}
public Map<String, String> getEndpointPeerServiceMapping() {
return endpointPeerServiceMapping;
}
@ -613,6 +629,8 @@ public class Config {
+ sqlNormalizerEnabled
+ ", kafkaClientPropagationEnabled="
+ kafkaClientPropagationEnabled
+ ", hystrixTagsEnabled="
+ hystrixTagsEnabled
+ ", endpointPeerServiceMapping="
+ endpointPeerServiceMapping
+ '}';

View File

@ -17,12 +17,19 @@
package io.opentelemetry.instrumentation.auto.hystrix;
import com.netflix.hystrix.HystrixInvokableInfo;
import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.instrumentation.api.decorator.BaseDecorator;
import io.opentelemetry.trace.Span;
public class HystrixDecorator extends BaseDecorator {
public static final HystrixDecorator DECORATE = new HystrixDecorator();
private final boolean extraTags;
private HystrixDecorator() {
extraTags = Config.get().isHystrixTagsEnabled();
}
public void onCommand(Span span, HystrixInvokableInfo<?> command, String methodName) {
if (command != null) {
String commandName = command.getCommandKey().name();
@ -32,9 +39,11 @@ public class HystrixDecorator extends BaseDecorator {
String spanName = groupName + "." + commandName + "." + methodName;
span.updateName(spanName);
span.setAttribute("hystrix.command", commandName);
span.setAttribute("hystrix.group", groupName);
span.setAttribute("hystrix.circuit-open", circuitOpen);
if (extraTags) {
span.setAttribute("hystrix.command", commandName);
span.setAttribute("hystrix.group", groupName);
span.setAttribute("hystrix.circuit-open", circuitOpen);
}
}
}
}

View File

@ -19,6 +19,7 @@ import static io.opentelemetry.auto.test.utils.TraceUtils.runUnderTrace
import com.netflix.hystrix.HystrixObservableCommand
import io.opentelemetry.auto.test.AgentTestRunner
import io.opentelemetry.auto.test.utils.ConfigUtils
import rx.Observable
import rx.schedulers.Schedulers
@ -26,6 +27,9 @@ class HystrixObservableChainTest extends AgentTestRunner {
static {
// Disable so failure testing below doesn't inadvertently change the behavior.
System.setProperty("hystrix.command.default.circuitBreaker.enabled", "false")
ConfigUtils.updateConfig {
System.setProperty("otel.hystrix.tags.enabled", "true")
}
// Uncomment for debugging:
// System.setProperty("hystrix.command.default.execution.timeout.enabled", "false")

View File

@ -21,6 +21,7 @@ import com.netflix.hystrix.HystrixObservable
import com.netflix.hystrix.HystrixObservableCommand
import com.netflix.hystrix.exception.HystrixRuntimeException
import io.opentelemetry.auto.test.AgentTestRunner
import io.opentelemetry.auto.test.utils.ConfigUtils
import java.util.concurrent.BlockingQueue
import java.util.concurrent.LinkedBlockingQueue
import rx.Observable
@ -30,6 +31,9 @@ class HystrixObservableTest extends AgentTestRunner {
static {
// Disable so failure testing below doesn't inadvertently change the behavior.
System.setProperty("hystrix.command.default.circuitBreaker.enabled", "false")
ConfigUtils.updateConfig {
System.setProperty("otel.hystrix.tags.enabled", "true")
}
// Uncomment for debugging:
// System.setProperty("hystrix.command.default.execution.timeout.enabled", "false")

View File

@ -19,6 +19,7 @@ import static io.opentelemetry.auto.test.utils.TraceUtils.runUnderTrace
import com.netflix.hystrix.HystrixCommand
import io.opentelemetry.auto.test.AgentTestRunner
import io.opentelemetry.auto.test.utils.ConfigUtils
import java.util.concurrent.BlockingQueue
import java.util.concurrent.LinkedBlockingQueue
import spock.lang.Timeout
@ -28,6 +29,9 @@ class HystrixTest extends AgentTestRunner {
static {
// Disable so failure testing below doesn't inadvertently change the behavior.
System.setProperty("hystrix.command.default.circuitBreaker.enabled", "false")
ConfigUtils.updateConfig {
System.setProperty("otel.hystrix.tags.enabled", "true")
}
// Uncomment for debugging:
// System.setProperty("hystrix.command.default.execution.timeout.enabled", "false")