Resolve service name at runtime when sending a span to Zipkin; fixes #749
This commit is contained in:
@@ -57,6 +57,7 @@ public class ServerPropertiesHostLocator implements HostLocator, EnvironmentAwar
|
||||
private Integer port; // Lazy assigned
|
||||
private Environment environment;
|
||||
|
||||
@Deprecated
|
||||
public ServerPropertiesHostLocator(ServerProperties serverProperties, String appName,
|
||||
ZipkinProperties zipkinProperties, InetUtils inetUtils) {
|
||||
this.serverProperties = serverProperties;
|
||||
@@ -70,6 +71,12 @@ public class ServerPropertiesHostLocator implements HostLocator, EnvironmentAwar
|
||||
}
|
||||
}
|
||||
|
||||
public ServerPropertiesHostLocator(ServerProperties serverProperties,
|
||||
Environment environment, ZipkinProperties zipkinProperties, InetUtils inetUtils) {
|
||||
this(serverProperties, "", zipkinProperties, inetUtils);
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Host locate(Span span) {
|
||||
String serviceName = getServiceName(span);
|
||||
@@ -119,7 +126,7 @@ public class ServerPropertiesHostLocator implements HostLocator, EnvironmentAwar
|
||||
serviceName = span.getProcessId();
|
||||
}
|
||||
else {
|
||||
serviceName = this.appName;
|
||||
serviceName = this.environment.getProperty("spring.application.name", "unknown");
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Span will contain serviceName [" + serviceName + "]");
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
@@ -114,12 +113,12 @@ public class SleuthStreamAutoConfiguration {
|
||||
@Autowired
|
||||
private InetUtils inetUtils;
|
||||
|
||||
@Value("${spring.application.name:unknown}")
|
||||
private String appName;
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Bean
|
||||
public HostLocator zipkinEndpointLocator() {
|
||||
return new ServerPropertiesHostLocator(this.serverProperties, this.appName, this.zipkinProperties,
|
||||
return new ServerPropertiesHostLocator(this.serverProperties, this.environment, this.zipkinProperties,
|
||||
this.inetUtils);
|
||||
}
|
||||
|
||||
@@ -140,8 +139,8 @@ public class SleuthStreamAutoConfiguration {
|
||||
@Autowired(required = false)
|
||||
private InetUtils inetUtils;
|
||||
|
||||
@Value("${spring.application.name:unknown}")
|
||||
private String appName;
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Autowired(required = false)
|
||||
private DiscoveryClient client;
|
||||
@@ -151,7 +150,7 @@ public class SleuthStreamAutoConfiguration {
|
||||
if (this.client != null) {
|
||||
return new DiscoveryClientHostLocator(this.client, this.zipkinProperties);
|
||||
}
|
||||
return new ServerPropertiesHostLocator(this.serverProperties, this.appName, this.zipkinProperties,
|
||||
return new ServerPropertiesHostLocator(this.serverProperties, this.environment, this.zipkinProperties,
|
||||
this.inetUtils);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user