Resolve service name at runtime when sending a span to Zipkin; fixes #749

This commit is contained in:
Marcin Grzejszczak
2017-10-18 16:18:41 +02:00
parent 70821f4dc3
commit d02c62bb44
9 changed files with 75 additions and 55 deletions

View File

@@ -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 + "]");

View File

@@ -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);
}