Remove trace decorator yaml config
DELETE
dd-java-agent/src/main/resources/dd-trace-decorators-default.yaml
-# Decorators are used to add extra information to span.
-# To modify, copy the file to dd-trace-decorators.yaml and make desired changes.
-# Could be DBServiceDecorator or HTTPServiceDecorator, etc.
-decorators:
- - type: HTTPComponent
- matchingTag: component
- matchingValue: okhttp
- - type: HTTPComponent
- matchingTag: component
- matchingValue: java-aws-sdk
- - type: ErrorFlag
- - type: DBTypeDecorator
- - type: DBStatementAsResourceName
- - type: OperationDecorator
- - type: Status404Decorator
- - type: URLAsResourceName

MODIFY
dd-java-agent/testing/src/main/java/datadog/trace/agent/test/AgentTestRunner.java
dd-java-agent/testing/src/main/java/datadog/trace/agent/test/AgentTestRunner.java
@@ -49,7 +49,7 @@ public abstract class AgentTestRunner extends Specification {
TEST_WRITER = new ListWriter();
TEST_TRACER = new DDTracer(TEST_WRITER);
- final List<AbstractDecorator> decorators = DDDecoratorsFactory.createFromResources();
+ final List<AbstractDecorator> decorators = DDDecoratorsFactory.createBuiltinDecorators();
for (final AbstractDecorator decorator : decorators) {
((DDTracer) TEST_TRACER).addDecorator(decorator);
}

MODIFY
dd-trace-ot/src/main/java/datadog/opentracing/DDTracer.java
dd-trace-ot/src/main/java/datadog/opentracing/DDTracer.java
@@ -67,7 +67,7 @@ public class DDTracer extends ThreadLocalScopeManager implements io.opentracing.
log.debug("Using config: {}", config);
// Create decorators from resource files
- final List<AbstractDecorator> decorators = DDDecoratorsFactory.createFromResources();
+ final List<AbstractDecorator> decorators = DDDecoratorsFactory.createBuiltinDecorators();
for (final AbstractDecorator decorator : decorators) {
log.debug("Loading decorator: {}", decorator.getClass().getSimpleName());
addDecorator(decorator);

MODIFY
dd-trace-ot/src/main/java/datadog/opentracing/decorators/DDDecoratorsFactory.java
dd-trace-ot/src/main/java/datadog/opentracing/decorators/DDDecoratorsFactory.java
package datadog.opentracing.decorators;
-import datadog.trace.common.util.ConfigUtils;
import java.util.ArrayList;
import java.util.List;
-import lombok.extern.slf4j.Slf4j;
-/** Create DDSpanDecorators from a valid configuration */
-@Slf4j
+/** Create DDSpanDecorators */
public class DDDecoratorsFactory {
-
- public static final String CONFIG_PATH = "dd-trace-decorators";
- public static String DECORATORS_PACKAGE = "datadog.opentracing.decorators.";
-
- /**
- * Create decorators from configuration
- *
- * @param decoratorsConfig
- * @return the list of instanciated and configured decorators
- */
- public static List<AbstractDecorator> create(
- final List<DecoratorsConfig.DDSpanDecoratorConfig> decoratorsConfig) {
- final List<AbstractDecorator> decorators = new ArrayList<>();
- for (final DecoratorsConfig.DDSpanDecoratorConfig decoratorConfig : decoratorsConfig) {
- if (decoratorConfig.getType() == null) {
- log.warn("Cannot create decorator without type from configuration {}", decoratorConfig);
- continue;
- }
-
- // Find class and create
- final Class<?> decoratorClass;
- try {
- decoratorClass = Class.forName(DECORATORS_PACKAGE + decoratorConfig.getType());
- } catch (final ClassNotFoundException e) {
- log.warn(
- "Cannot create decorator as the class {} is not defined. Provided configuration {}",
- decoratorConfig);
- continue;
- }
-
- AbstractDecorator decorator = null;
- try {
- decorator = (AbstractDecorator) decoratorClass.getConstructor().newInstance();
- } catch (final Exception e) {
- log.warn(
- "Cannot create decorator as we could not invoke the default constructor. Provided configuration {}",
- decoratorConfig);
- continue;
- }
-
- // Fill with config values
- if (decoratorConfig.getMatchingTag() != null) {
- decorator.setMatchingTag(decoratorConfig.getMatchingTag());
- }
- if (decoratorConfig.getMatchingValue() != null) {
- decorator.setMatchingValue(decoratorConfig.getMatchingValue());
- }
- if (decoratorConfig.getSetTag() != null) {
- decorator.setSetTag(decoratorConfig.getSetTag());
- }
- if (decoratorConfig.getSetValue() != null) {
- decorator.setSetValue(decoratorConfig.getSetValue());
- }
-
- decorators.add(decorator);
- }
- return decorators;
- }
-
- public static List<AbstractDecorator> createFromResources() {
- final List<AbstractDecorator> result;
- final DecoratorsConfig config =
- ConfigUtils.loadConfigFromResource(CONFIG_PATH, DecoratorsConfig.class);
- if (config == null) {
- result = createBuiltinDecorators();
- } else {
- result = DDDecoratorsFactory.create(config.getDecorators());
- }
- return result;
- }
-
- private static List<AbstractDecorator> createBuiltinDecorators() {
+ public static List<AbstractDecorator> createBuiltinDecorators() {
List<AbstractDecorator> builtin = new ArrayList<AbstractDecorator>(8);
{
final HTTPComponent httpDecorator1 = new HTTPComponent();

DELETE
dd-trace-ot/src/main/java/datadog/opentracing/decorators/DecoratorsConfig.java
-package datadog.opentracing.decorators;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
-import java.util.List;
-
-@JsonIgnoreProperties(ignoreUnknown = true)
-class DecoratorsConfig {
- private List<DDSpanDecoratorConfig> decorators;
-
- public List<DDSpanDecoratorConfig> getDecorators() {
- return decorators;
- }
-
- public void setDecorators(final List<DDSpanDecoratorConfig> decorators) {
- this.decorators = decorators;
- }
-
- @Override
- public String toString() {
- try {
- return new ObjectMapper(new YAMLFactory()).writeValueAsString(this);
- } catch (final JsonProcessingException e) {
- // FIXME better toString() while config object stabilized
- return null;
- }
- }
-
- static class DDSpanDecoratorConfig {
-
- private String type;
-
- private String matchingTag;
-
- private String matchingValue;
-
- private String setTag;
-
- private String setValue;
-
- public String getMatchingTag() {
- return matchingTag;
- }
-
- public void setMatchingTag(final String matchingTag) {
- this.matchingTag = matchingTag;
- }
-
- public String getMatchingValue() {
- return matchingValue;
- }
-
- public void setMatchingValue(final String matchingValue) {
- this.matchingValue = matchingValue;
- }
-
- public String getSetTag() {
- return setTag;
- }
-
- public void setSetTag(final String setTag) {
- this.setTag = setTag;
- }
-
- public String getSetValue() {
- return setValue;
- }
-
- public void setSetValue(final String setValue) {
- this.setValue = setValue;
- }
-
- public void setType(final String type) {
- this.type = type;
- }
-
- public String getType() {
- return type;
- }
-
- @Override
- public String toString() {
- try {
- return new ObjectMapper(new YAMLFactory()).writeValueAsString(this);
- } catch (final JsonProcessingException e) {
- return null;
- }
- }
- }
-}

MODIFY
dd-trace-ot/src/test/groovy/datadog/trace/DDTraceConfigTest.groovy
dd-trace-ot/src/test/groovy/datadog/trace/DDTraceConfigTest.groovy
@@ -129,7 +129,7 @@ class DDTraceConfigTest extends Specification {
tracer.sampler instanceof AllSampler
tracer.writer.toString() == "DDAgentWriter { api=DDApi { tracesEndpoint=http://localhost:8126/v0.3/traces } }"
- tracer.spanContextDecorators.size() == 2
+ tracer.spanContextDecorators.size() == 6
}
@Unroll

MODIFY
dd-trace-ot/src/test/java/datadog/opentracing/resolver/TracerResolverTest.java
dd-trace-ot/src/test/java/datadog/opentracing/resolver/TracerResolverTest.java
@@ -3,43 +3,15 @@ package datadog.opentracing.resolver;
import static org.assertj.core.api.Assertions.assertThat;
import datadog.opentracing.DDTracer;
-import datadog.opentracing.decorators.AbstractDecorator;
-import datadog.opentracing.decorators.HTTPComponent;
-import datadog.opentracing.decorators.URLAsResourceName;
import io.opentracing.Tracer;
import io.opentracing.contrib.tracerresolver.TracerResolver;
import io.opentracing.noop.NoopTracerFactory;
import io.opentracing.util.GlobalTracer;
import java.lang.reflect.Field;
-import java.util.List;
import org.junit.Test;
public class TracerResolverTest {
- @Test
- public void testResolve() {
- final DDTracerResolver tracerResolver = new DDTracerResolver();
- final DDTracer tracer = (DDTracer) tracerResolver.resolve();
-
- // for HTTP decorators
- List<AbstractDecorator> decorators = tracer.getSpanContextDecorators("component");
-
- assertThat(decorators.size()).isEqualTo(2);
- AbstractDecorator decorator = decorators.get(0);
- assertThat(decorator.getClass()).isEqualTo(HTTPComponent.class);
- final HTTPComponent httpServiceDecorator = (HTTPComponent) decorator;
- assertThat(httpServiceDecorator.getMatchingTag()).isEqualTo("component");
- assertThat(httpServiceDecorator.getMatchingValue()).isEqualTo("hello");
- assertThat(httpServiceDecorator.getSetValue()).isEqualTo("world");
-
- // for URL decorators
- decorators = tracer.getSpanContextDecorators("http.url");
- assertThat(decorators.size()).isEqualTo(1);
-
- decorator = decorators.get(0);
- assertThat(decorator.getClass()).isEqualTo(URLAsResourceName.class);
- }
-
@Test
public void testResolveTracer() throws Exception {
final Field tracerField = GlobalTracer.class.getDeclaredField("tracer");

DELETE
dd-trace-ot/src/test/resources/dd-trace-decorators.yaml
-decorators:
- - type: HTTPComponent
- matchingValue: hello
- setValue: world
- - type: HTTPComponent
- matchingValue: foo
- setValue: bar
- - type: URLAsResourceName
\ No newline at end of file

Remove trace decorator yaml config