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); 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 * @deprecated This method should only be used internally. Use the instance getter instead {@link
* #isJmxFetchIntegrationEnabled(SortedSet, boolean)}. * #isJmxFetchIntegrationEnabled(SortedSet, boolean)}.

View File

@ -4,31 +4,44 @@ import datadog.trace.api.Config;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import lombok.extern.slf4j.Slf4j;
/** Create DDSpanDecorators */ /** Create DDSpanDecorators */
@Slf4j
public class DDDecoratorsFactory { public class DDDecoratorsFactory {
public static List<AbstractDecorator> createBuiltinDecorators() { public static List<AbstractDecorator> createBuiltinDecorators() {
final List<AbstractDecorator> decorators = final List<AbstractDecorator> decorators = new ArrayList<>();
new ArrayList<>(
Arrays.asList(
new AnalyticsSampleRateDecorator(),
new DBStatementAsResourceName(),
new DBTypeDecorator(),
new ErrorFlag(),
new ForceManualDropDecorator(),
new ForceManualKeepDecorator(),
new OperationDecorator(),
new PeerServiceDecorator(),
new ResourceNameDecorator(),
new ServiceNameDecorator(),
new ServiceNameDecorator("service", false),
new ServletContextDecorator(),
new SpanTypeDecorator(),
new Status404Decorator(),
new Status5XXDecorator(),
new URLAsResourceName()));
for (final AbstractDecorator decorator :
Arrays.asList(
new AnalyticsSampleRateDecorator(),
new DBStatementAsResourceName(),
new DBTypeDecorator(),
new ErrorFlag(),
new ForceManualDropDecorator(),
new ForceManualKeepDecorator(),
new OperationDecorator(),
new PeerServiceDecorator(),
new ResourceNameDecorator(),
new ServiceNameDecorator(),
new ServiceNameDecorator("service", false),
new ServletContextDecorator(),
new SpanTypeDecorator(),
new Status404Decorator(),
new Status5XXDecorator(),
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()) { for (final String splitByTag : Config.get().getSplitByTags()) {
decorators.add(new ServiceNameDecorator(splitByTag, true)); decorators.add(new ServiceNameDecorator(splitByTag, true));
} }

View File

@ -470,4 +470,72 @@ class SpanDecoratorTest extends DDSpecification {
then: then:
span.resourceName == "some-statement" 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"
}
} }