javaspring-bootnetflix-feign

Access URITemplate or RequestLine value in Feign RequestInterceptor / RequestTemplate


I'm developing an app against a cloud application that has hard api rate limits in place. In order to have my team get a feeling for how close we are in regards to those limits I want to count all API calls made from our app in a meaningful way.

We use Feign as access layer, and I was hoping to be able to use the RequestInterceptor to count the different API endpoints we call:

RequestInterceptor ri = rq -> addStatistics(rq.url());

Now this does not work, as the resulting URLs almost always count "1" afterwards, as they already contain all resolved path variables, so I get counts for

1 - /something/id1valueverycryptic/get
1 - /something/anothercrypticidkey/get

and so on.

I was hoping to somehow get access to either the @ResuqestLine mapping value (GET /something/{id}/get) or at least the uri template pre-resolve (/somethine/{id}/get)

Is there a way to do this?

Thanks!


Solution

  • Maybe you could try using custom feign InvocationHandlerFactory.

    I've managed to log RequestInterceptor using code like this:

    Be careful and check if you feign configuration wasn't more complex and in that case extend classes as needed.