Skip to content

Commit 89ca7d7

Browse files
jwcarmanmarcingrzejszczak
authored andcommitted
The serviceName is not being resolved properly (#1183)
with this change if the service name is empty we will set it to `default`
1 parent 14cdaf5 commit 89ca7d7

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/autoconfig/TraceAutoConfiguration.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import brave.propagation.Propagation;
3131
import brave.propagation.ThreadLocalCurrentTraceContext;
3232
import brave.sampler.Sampler;
33+
import org.springframework.util.StringUtils;
3334
import zipkin2.Span;
3435
import zipkin2.reporter.Reporter;
3536

@@ -62,6 +63,11 @@ public class TraceAutoConfiguration {
6263
*/
6364
public static final String TRACER_BEAN_NAME = "tracer";
6465

66+
/**
67+
* Default value used for service name if none provided.
68+
*/
69+
public static final String DEFAULT_SERVICE_NAME = "default";
70+
6571
@Autowired(required = false)
6672
List<SpanAdjuster> spanAdjusters = new ArrayList<>();
6773

@@ -83,7 +89,8 @@ Tracing tracing(
8389
Reporter<zipkin2.Span> reporter, Sampler sampler, ErrorParser errorParser,
8490
SleuthProperties sleuthProperties) {
8591
Tracing.Builder builder = Tracing.newBuilder().sampler(sampler)
86-
.errorParser(errorParser).localServiceName(serviceName)
92+
.errorParser(errorParser)
93+
.localServiceName(StringUtils.isEmpty(serviceName) ? DEFAULT_SERVICE_NAME : serviceName)
8794
.propagationFactory(factory).currentTraceContext(currentTraceContext)
8895
.spanReporter(adjustedReporter(reporter))
8996
.traceId128Bit(sleuthProperties.isTraceId128())

spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/autoconfig/TraceAutoConfigurationPropagationCustomizationTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ public void allowsCustomization() {
3434
});
3535
}
3636

37+
@Test
38+
public void defaultValueUsedWhenApplicationNameNotSet() {
39+
this.contextRunner.withPropertyValues("spring.application.name=")
40+
.run((context) -> {
41+
BDDAssertions.then(context.getBean(Propagation.Factory.class))
42+
.isEqualTo(B3Propagation.FACTORY);
43+
});
44+
}
45+
3746
@Test
3847
public void allowsCustomizationOfBuilder() {
3948
this.contextRunner.withPropertyValues("spring.sleuth.baggage-keys=my-baggage")

0 commit comments

Comments
 (0)