简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM