Spring-cloud-sleuth: Support for non-webapps and/or non-actuator apps

Created on 20 Aug 2015  路  8Comments  路  Source: spring-cloud/spring-cloud-sleuth

Currently we try to determine the "endpoint" (in Zipkin terms but the code is in core) by looking at ServerProperties. What if there isn't one? Maybe the ApplicationContext id is a good enough replacement?

bug enhancement

All 8 comments

Endpoint takes three params:

  1. ipv4: we can in the worst case use non-loopback lookup ala https://github.com/spring-cloud/spring-cloud-commons/issues/47
  2. port: 0?
  3. servicename: if spring.application.name isn't set, we could use ApplicationContext id

I think this is superseded by the *Locator interfaces we provided. The only problem is that we default to span.getProcessId() if it is not-null (which might have very little to do with the actual service name).

Currently if ServerProperties is null the code will provide defaults:

public class ServerPropertiesEndpointLocator implements EndpointLocator {

    private final ServerProperties serverProperties;
    private final String appName;
    private Integer port;

    public ServerPropertiesEndpointLocator(ServerProperties serverProperties,
                                                                                String appName) {
        this.serverProperties = serverProperties;
        this.appName = appName;
    }

    @Override
    public Endpoint local() {
        int address = getAddress();
        Integer port = getPort();
        return Endpoint.create(this.appName, address, port);
    }

    @EventListener(EmbeddedServletContainerInitializedEvent.class)
    public void grabPort(EmbeddedServletContainerInitializedEvent event) {
        this.port = event.getEmbeddedServletContainer().getPort();
    }

    private Integer getPort() {
        if (this.port!=null) {
            return this.port;
        }
        Integer port;
        if (this.serverProperties!=null && this.serverProperties.getPort() != null) {
            port = this.serverProperties.getPort();
        }
        else {
            port = 8080;
        }
        return port;
    }

    private int getAddress() {
        if (this.serverProperties!=null && this.serverProperties.getAddress() != null) {
            return InetUtils.getIpAddressAsInt(this.serverProperties.getAddress().getHostAddress());
        }
        else {
            return 127 << 24 | 1;
        }
    }
}

so theoretically the code works without ServerProperties - even though it returns some arbitrary values

Since Camden.SR3 non-webapps do not start anymore, because there is a hard dependency on HttpTraceKeysInjector. If you like I can set up a small demo project.

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.cloud.sleuth.instrument.web.HttpTraceKeysInjector' available at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:353) ~[spring-beans-4.3.5.RELEASE.jar!/:4.3.5.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:351) at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:340) at org.springframework.cloud.sleuth.instrument.web.client.feign.TraceFeignClient.getKeysInjector(TraceFeignClient.java:111) ~[spring-cloud-sleuth-core-1.1.0.RELEASE.jar!/:1.1.0.RELEASE] at org.springframework.cloud.sleuth.instrument.web.client.feign.TraceFeignClient.addRequestTags(TraceFeignClient.java:105) at org.springframework.cloud.sleuth.instrument.web.client.feign.TraceFeignClient.execute(TraceFeignClient.java:75) at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:97) ~[feign-core-9.3.1.jar!/:na] at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76) at feign.hystrix.HystrixInvocationHandler$1.run(HystrixInvocationHandler.java:108) ~[feign-hystrix-9.3.1.jar!/:na] at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:301) ~[hystrix-core-1.5.6.jar!/:1.5.6] at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:297) at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46) ~[rxjava-1.1.10.jar!/:1.1.10] ... 27 common frames omitted

Yeah please do - that's really unfortunate :/

I uploaded a demo project: https://github.com/otrosien/spring-cloud-sleuth-issue-32
You can also look at the gradle test report here: https://otrosien.github.io/spring-cloud-sleuth-issue-32/index.html

I need to correct myself: The application starts up fine, but when you try to use the FeignClient, it fails.

thumbs-up!

You can check out the snapshots but now it seems that it should work ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nickcodefresh picture nickcodefresh  路  7Comments

apolischuk picture apolischuk  路  7Comments

longting picture longting  路  7Comments

marcingrzejszczak picture marcingrzejszczak  路  8Comments

gasperlf picture gasperlf  路  4Comments