The serviceName is not being resolved properly (#1183)

with this change if the service name is empty we will set it to `default`
This commit is contained in:
James Carman
2019-01-15 10:41:44 -05:00
committed by Marcin Grzejszczak
parent 14cdaf529e
commit 89ca7d7759
2 changed files with 17 additions and 1 deletions

View File

@@ -30,6 +30,7 @@ import brave.propagation.ExtraFieldPropagation;
import brave.propagation.Propagation;
import brave.propagation.ThreadLocalCurrentTraceContext;
import brave.sampler.Sampler;
import org.springframework.util.StringUtils;
import zipkin2.Span;
import zipkin2.reporter.Reporter;
@@ -62,6 +63,11 @@ public class TraceAutoConfiguration {
*/
public static final String TRACER_BEAN_NAME = "tracer";
/**
* Default value used for service name if none provided.
*/
public static final String DEFAULT_SERVICE_NAME = "default";
@Autowired(required = false)
List<SpanAdjuster> spanAdjusters = new ArrayList<>();
@@ -83,7 +89,8 @@ public class TraceAutoConfiguration {
Reporter<zipkin2.Span> reporter, Sampler sampler, ErrorParser errorParser,
SleuthProperties sleuthProperties) {
Tracing.Builder builder = Tracing.newBuilder().sampler(sampler)
.errorParser(errorParser).localServiceName(serviceName)
.errorParser(errorParser)
.localServiceName(StringUtils.isEmpty(serviceName) ? DEFAULT_SERVICE_NAME : serviceName)
.propagationFactory(factory).currentTraceContext(currentTraceContext)
.spanReporter(adjustedReporter(reporter))
.traceId128Bit(sleuthProperties.isTraceId128())

View File

@@ -34,6 +34,15 @@ public class TraceAutoConfigurationPropagationCustomizationTests {
});
}
@Test
public void defaultValueUsedWhenApplicationNameNotSet() {
this.contextRunner.withPropertyValues("spring.application.name=")
.run((context) -> {
BDDAssertions.then(context.getBean(Propagation.Factory.class))
.isEqualTo(B3Propagation.FACTORY);
});
}
@Test
public void allowsCustomizationOfBuilder() {
this.contextRunner.withPropertyValues("spring.sleuth.baggage-keys=my-baggage")