Allow service name mapping to apply without setting the tag.
Previously the mapping only applied when the `service.name` tag was set, not on the default or configured service name.
This commit is contained in:
parent
1aaa3cafeb
commit
de5d108afc
|
@ -57,6 +57,8 @@ public class DDTracer implements io.opentracing.Tracer {
|
|||
|
||||
/** A set of tags that are added to every span */
|
||||
private final Map<String, String> spanTags;
|
||||
/** A configured mapping of service names to update with new values */
|
||||
private final Map<String, String> serviceNameMappings;
|
||||
|
||||
/** Span context decorators */
|
||||
private final Map<String, List<AbstractDecorator>> spanContextDecorators =
|
||||
|
@ -116,6 +118,7 @@ public class DDTracer implements io.opentracing.Tracer {
|
|||
this.writer.start();
|
||||
this.sampler = sampler;
|
||||
this.spanTags = defaultSpanTags;
|
||||
this.serviceNameMappings = serviceNameMappings;
|
||||
|
||||
try {
|
||||
Runtime.getRuntime()
|
||||
|
@ -522,6 +525,10 @@ public class DDTracer implements io.opentracing.Tracer {
|
|||
serviceName = DDTracer.this.serviceName;
|
||||
}
|
||||
|
||||
if (serviceNameMappings.containsKey(serviceName)) {
|
||||
serviceName = serviceNameMappings.get(serviceName);
|
||||
}
|
||||
|
||||
final String operationName =
|
||||
this.operationName != null ? this.operationName : this.resourceName;
|
||||
|
||||
|
|
|
@ -5,12 +5,14 @@ import datadog.opentracing.DDTracer
|
|||
import datadog.opentracing.SpanFactory
|
||||
import datadog.trace.api.DDSpanTypes
|
||||
import datadog.trace.api.DDTags
|
||||
import datadog.trace.common.sampling.AllSampler
|
||||
import datadog.trace.common.writer.LoggingWriter
|
||||
import io.opentracing.tag.StringTag
|
||||
import io.opentracing.tag.Tags
|
||||
import spock.lang.Specification
|
||||
|
||||
import static datadog.opentracing.DDTracer.UNASSIGNED_DEFAULT_SERVICE_NAME
|
||||
import static java.util.Collections.emptyMap
|
||||
|
||||
class SpanDecoratorTest extends Specification {
|
||||
def tracer = new DDTracer(new LoggingWriter())
|
||||
|
@ -74,6 +76,23 @@ class SpanDecoratorTest extends Specification {
|
|||
"other-context" | "my-service" | "my-service"
|
||||
}
|
||||
|
||||
def "default or configured service name can be remapped without setting tag"() {
|
||||
setup:
|
||||
tracer = new DDTracer(serviceName, new LoggingWriter(), new AllSampler(), emptyMap(), mapping, emptyMap())
|
||||
|
||||
when:
|
||||
def span = tracer.buildSpan("some span").start()
|
||||
|
||||
then:
|
||||
span.serviceName == expected
|
||||
|
||||
where:
|
||||
serviceName | expected | mapping
|
||||
UNASSIGNED_DEFAULT_SERVICE_NAME | UNASSIGNED_DEFAULT_SERVICE_NAME | ["other-service-name": "other-service"]
|
||||
UNASSIGNED_DEFAULT_SERVICE_NAME | "new-service" | [(UNASSIGNED_DEFAULT_SERVICE_NAME): "new-service"]
|
||||
"other-service-name" | "other-service" | ["other-service-name": "other-service"]
|
||||
}
|
||||
|
||||
def "set operation name"() {
|
||||
when:
|
||||
Tags.COMPONENT.set(span, component)
|
||||
|
|
Loading…
Reference in New Issue