1
votes

I'm trying to get spring slueth to propogate the trace ids through our systems.

when checking the logs on the other service I noticed new Ids being generated.

I thought this may be due to my using a Feign builder and I was already using a okHttpClient.

I came across the following:

https://github.com/spring-cloud/spring-cloud-sleuth/issues/594

How to implement Sleuth Tracing With Feign.Builder?

I have my beans set up like the following:

@Configuration
@RequiredArgsConstructor
public class OkHttpConfig {

  private final Properties properties;

  @Bean
  public OkHttpClient okHttpClient() {
    return new Builder()
        .connectTimeout(properties.getHttpTimeoutMillis(), TimeUnit.MILLISECONDS)
        .readTimeout(properties.getHttpTimeoutMillis(), TimeUnit.MILLISECONDS)
        .writeTimeout(properties.getHttpTimeoutMillis(), TimeUnit.MILLISECONDS)
        .connectionPool(new ConnectionPool(properties.getHttpPoolSize(),
            properties.getHttpKeepAliveMillis(), TimeUnit.MILLISECONDS))
        .build();
  }
@Configuration
public class HttpClientConfiguration {

  @Autowired
  private Properties properties;

  @Autowired
  private Client client;

  @Bean
  public SomeClient SomeClient(Client client, ObjectMapper objectMapper {
    return feignClient(properties.getUrl(), SomeClient.class, client,
            objectMapper);
  }

  public static <T> T feignClient(String baseUrl, Class<T> clientClass,
      Client client, ObjectMapper objectMapper) {
    return Feign.builder()
        .client(client)
        .decoder(new JacksonDecoder(objectMapper))
        .encoder(new JacksonEncoder(objectMapper))
        .target(clientClass, baseUrl);
  }

I expected the client to be wrapped in a trace implementation but i kept getting the following error

Unsatisfied dependency expressed through field 'client'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type 'feign.Client' available: 
expected at least 1 bean which qualifies as autowire candidate.Dependency annotations:

Using the following versions:

Spring boot 2.1.2.RELEASE

org.springframework.cloud:spring-cloud-sleuth:2.1.0.RELEASE

1
If you're not using Sleuth you don't have this issue? - Marcin Grzejszczak
No, as I wasn't passing in a Client instead I was passing around OkHttpClient which spring recognised as bean. - YK-47
I'm asking cause maybe it has nothing to do with Sleuth. Try doing the same without Sleuth and see if an exception is thrown. - Marcin Grzejszczak
Same issue without Sleuth. I also have intellJ warning "Could not autowire. No beans of 'Client' type found. more... (⌘F1)" - YK-47
That's what I thought. So I guess you can rename the issue and untag sleuth cause it has nothing to do with it. - Marcin Grzejszczak

1 Answers

0
votes

In the chat (https://chat.stackoverflow.com/rooms/188411/discussion-between-yk-47-and-marcin-grzejszczak) we've analyzed the current setup. It was missing bean definition and most importantly the spring-cloud starter for open feign.