Only apply service name mapping on finish
If done in the decorator, it would be applied twice.  Only want it done once.
MODIFY
dd-trace-ot/src/main/java/datadog/opentracing/decorators/DDDecoratorsFactory.java
dd-trace-ot/src/main/java/datadog/opentracing/decorators/DDDecoratorsFactory.java
@@ -24,7 +24,7 @@ public class DDDecoratorsFactory {
httpDecorator2,
new OperationDecorator(),
new ResourceNameDecorator(),
- new ServiceNameDecorator(mappings),
+ new ServiceNameDecorator(),
new ServletContextDecorator(),
new SpanTypeDecorator(),
new Status5XXDecorator(),

MODIFY
dd-trace-ot/src/main/java/datadog/opentracing/decorators/ServiceNameDecorator.java
dd-trace-ot/src/main/java/datadog/opentracing/decorators/ServiceNameDecorator.java
@@ -2,25 +2,17 @@ package datadog.opentracing.decorators;
import datadog.opentracing.DDSpanContext;
import datadog.trace.api.DDTags;
-import java.util.Map;
public class ServiceNameDecorator extends AbstractDecorator {
- private final Map<String, String> mappings;
-
- public ServiceNameDecorator(final Map<String, String> mappings) {
+ public ServiceNameDecorator() {
super();
this.setMatchingTag(DDTags.SERVICE_NAME);
- this.mappings = mappings;
}
@Override
public boolean shouldSetTag(final DDSpanContext context, final String tag, final Object value) {
- if (mappings.containsKey(String.valueOf(value))) {
- context.setServiceName(mappings.get(String.valueOf(value)));
- } else {
context.setServiceName(String.valueOf(value));
- }
return false;
}
}

MODIFY
dd-trace-ot/src/test/groovy/datadog/opentracing/decorators/SpanDecoratorTest.groovy
dd-trace-ot/src/test/groovy/datadog/opentracing/decorators/SpanDecoratorTest.groovy
@@ -42,10 +42,11 @@ class SpanDecoratorTest extends Specification {
def "set service name"() {
setup:
- tracer.addDecorator(new ServiceNameDecorator(mapping))
+ tracer = new DDTracer("wrong-service", new LoggingWriter(), new AllSampler(), emptyMap(), mapping, emptyMap())
when:
- span.setTag(DDTags.SERVICE_NAME, name)
+ def span = tracer.buildSpan("some span").withTag(DDTags.SERVICE_NAME, name).start()
+ span.finish()
then:
span.getServiceName() == expected

MODIFY
dd-trace-ot/src/test/groovy/datadog/trace/DDTraceConfigTest.groovy
dd-trace-ot/src/test/groovy/datadog/trace/DDTraceConfigTest.groovy
package datadog.trace
import datadog.opentracing.DDTracer
-import datadog.opentracing.decorators.ServiceNameDecorator
import datadog.trace.common.DDTraceConfig
import datadog.trace.common.sampling.AllSampler
import datadog.trace.common.writer.DDAgentWriter
@@ -119,14 +118,11 @@ class DDTraceConfigTest extends Specification {
when:
def tracer = new DDTracer()
- ServiceNameDecorator decorator = tracer.spanContextDecorators.values().flatten().find {
- it instanceof ServiceNameDecorator
- }
def taggedHeaders = tracer.registry.codecs.values().first().taggedHeaders
then:
tracer.spanTags == map
- decorator.mappings == map
+ tracer.serviceNameMappings == map
taggedHeaders == map
where:

Only apply service name mapping on finish

If done in the decorator, it would be applied twice.  Only want it done once.