Disable decorators via config

This commit is contained in:
Laplie Anderson 2019-12-19 13:02:59 -05:00
parent fb8f7af342
commit 712a5c1483
3 changed files with 104 additions and 19 deletions

View File

@ -596,6 +596,10 @@ public class Config {
return jmxFetchIntegrationEnabled(integrationNames, defaultEnabled);
}
public boolean isDecoratorEnabled(final String name) {
return getBooleanSettingFromEnvironment("trace." + name.toLowerCase() + ".enabled", true);
}
/**
* @deprecated This method should only be used internally. Use the instance getter instead {@link
* #isJmxFetchIntegrationEnabled(SortedSet, boolean)}.

View File

@ -4,13 +4,16 @@ import datadog.trace.api.Config;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
/** Create DDSpanDecorators */
@Slf4j
public class DDDecoratorsFactory {
public static List<AbstractDecorator> createBuiltinDecorators() {
final List<AbstractDecorator> decorators =
new ArrayList<>(
final List<AbstractDecorator> decorators = new ArrayList<>();
for (final AbstractDecorator decorator :
Arrays.asList(
new AnalyticsSampleRateDecorator(),
new DBStatementAsResourceName(),
@ -27,8 +30,18 @@ public class DDDecoratorsFactory {
new SpanTypeDecorator(),
new Status404Decorator(),
new Status5XXDecorator(),
new URLAsResourceName()));
new URLAsResourceName())) {
if (Config.get().isDecoratorEnabled(decorator.getClass().getSimpleName())) {
decorators.add(decorator);
} else {
log.debug("{} disabled", decorator.getClass().getSimpleName());
}
}
// SplitByTags purposely does not check for ServiceNameDecorator being enabled
// This allows for ServiceNameDecorator to be disabled above while keeping SplitByTags
// SplitByTags can be disable by removing SplitByTags config
for (final String splitByTag : Config.get().getSplitByTags()) {
decorators.add(new ServiceNameDecorator(splitByTag, true));
}

View File

@ -470,4 +470,72 @@ class SpanDecoratorTest extends DDSpecification {
then:
span.resourceName == "some-statement"
}
def "disable decorator via config"() {
setup:
ConfigUtils.updateConfig {
System.setProperty("dd.trace." + PeerServiceDecorator.getSimpleName().toLowerCase() + ".enabled", "false")
}
tracer = new DDTracer(
"some-service",
new LoggingWriter(),
new AllSampler(),
"some-runtime-id",
emptyMap(),
emptyMap(),
emptyMap(),
emptyMap()
)
when:
def span = tracer.buildSpan("some span").withTag(Tags.PEER_SERVICE.key, "peer-service").start()
span.finish()
then:
span.getServiceName() == "some-service"
cleanup:
ConfigUtils.updateConfig {
System.clearProperty("dd.trace." + PeerServiceDecorator.getSimpleName().toLowerCase() + ".enabled")
}
}
def "disabling service decorator does not disable split by tags"() {
setup:
ConfigUtils.updateConfig {
System.setProperty("dd.trace." + ServiceNameDecorator.getSimpleName().toLowerCase() + ".enabled", "false")
}
tracer = new DDTracer(
"some-service",
new LoggingWriter(),
new AllSampler(),
"some-runtime-id",
emptyMap(),
emptyMap(),
emptyMap(),
emptyMap()
)
when:
def span = tracer.buildSpan("some span").withTag(tag, name).start()
span.finish()
then:
span.getServiceName() == expected
cleanup:
ConfigUtils.updateConfig {
System.clearProperty("dd.trace." + ServiceNameDecorator.getSimpleName().toLowerCase() + ".enabled")
}
where:
tag | name | expected
DDTags.SERVICE_NAME | "new-service" | "some-service"
"service" | "new-service" | "some-service"
"sn.tag1" | "new-service" | "new-service"
}
}