Only apply service name mapping on finish
If done in the decorator, it would be applied twice. Only want it done once.
This commit is contained in:
parent
7807615605
commit
5fe08d20fc
|
@ -24,7 +24,7 @@ public class DDDecoratorsFactory {
|
|||
httpDecorator2,
|
||||
new OperationDecorator(),
|
||||
new ResourceNameDecorator(),
|
||||
new ServiceNameDecorator(mappings),
|
||||
new ServiceNameDecorator(),
|
||||
new ServletContextDecorator(),
|
||||
new SpanTypeDecorator(),
|
||||
new Status5XXDecorator(),
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
context.setServiceName(String.valueOf(value));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
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:
|
||||
|
|
Loading…
Reference in New Issue