'Use Micrometer with OpenFeign in spring-boot application

The OpenApi documentation says that it supports micrometer. How does the integration works? I could not find anything except this little documentation.

I have a FeignClient in a spring boot application

@FeignClient(name = "SomeService", url = "xxx", configuration = FeignConfiguration.class)
public interface SomeService {

    @GET
    @Path("/something")
    Something getSomething();
}

with the configuration

public class FeignConfiguration {
    @Bean
    public Capability capability() {
        return new MicrometerCapability();
    }
}

and the micrometer integration as a dependency

<dependency>
    <groupId>io.github.openfeign</groupId>
    <artifactId>feign-micrometer</artifactId>
    <version>10.12</version>
</dependency>

The code makes a call but I could not find any new metrics via the actuator overview, expecting some general information about my HTTP requests. What part is missing?



Solution 1:[1]

Update

I added the support for this to spring-cloud-openfeign. After the next release (2020.0.2), if micrometer is set-up, the only thing you need to do is putting feign-micrometer onto your classpath.

Old answer

I'm not sure if you do but I recommend to use spring-cloud-openfeign which autoconfigures Feign components for you. Unfortunately, it seems it does not autoconfigure Capability (that's one reason why your solution does not work) so you need to do it manually, please see the docs how to do it.

I was able to make this work combining the examples in the OpenFeign and Spring Cloud OpenFeign docs:

@Import(FeignClientsConfiguration.class)
class FooController {
    private final FooClient fooClient;

    public FooController(Decoder decoder, Encoder encoder, Contract contract, MeterRegistry meterRegistry) {
        this.fooClient = Feign.builder()
                .encoder(encoder)
                .decoder(decoder)
                .contract(contract)
                .addCapability(new MicrometerCapability(meterRegistry))
                .target(FooClient.class, "https://PROD-SVC");
    }
}

What I did:

  • Used spring-cloud-openfeign
  • Added feign-micrometer (see feign-bom)
  • Created the client in the way you can see above Importing FeignClientsConfiguration and passing MeterRegistry to MicrometerCapability are vital

After these, and calling the client, I had new metrics:

  • feign.Client
  • feign.Feign
  • feign.codec.Decoder
  • feign.codec.Decoder.response_size

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1