Disable decorators via config
This commit is contained in:
parent
fb8f7af342
commit
712a5c1483
|
@ -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)}.
|
||||||
|
|
|
@ -4,13 +4,16 @@ 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<>(
|
|
||||||
|
for (final AbstractDecorator decorator :
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
new AnalyticsSampleRateDecorator(),
|
new AnalyticsSampleRateDecorator(),
|
||||||
new DBStatementAsResourceName(),
|
new DBStatementAsResourceName(),
|
||||||
|
@ -27,8 +30,18 @@ public class DDDecoratorsFactory {
|
||||||
new SpanTypeDecorator(),
|
new SpanTypeDecorator(),
|
||||||
new Status404Decorator(),
|
new Status404Decorator(),
|
||||||
new Status5XXDecorator(),
|
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()) {
|
for (final String splitByTag : Config.get().getSplitByTags()) {
|
||||||
decorators.add(new ServiceNameDecorator(splitByTag, true));
|
decorators.add(new ServiceNameDecorator(splitByTag, true));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue