Need to put some custom authentication header using interceptor which requires full endpoint that's declared with @FeignClient(url) like http://localhost:8080/person/get/12. RequestTemplate does not provide full endpoint.
Kindly suggest. Thanks
Comment From: sdujanic
We are also using interceptors for AWS X-Ray call traces and since RequestTemplate does not provide full path our traces are not grouped. Each trace is shown separately making the tracing meaningless because gathered data is scattered all over the place.
Comment From: vforvikash
I've added url endpoint to the headers using @RequestMapping on method level.
Comment From: aaronjwhiteside
Assuming that the url in @FeignClient is configured via a property, you can use the same property when creating your RequestInterceptor Bean..
@FeignClient(url="${url.property.here}")
@Bean
public MyRequestInterceptor myRequestInterceptor(@Value("${url.property.here}") final String url) {
return new MyRequestInterceptor(url);
}
Comment From: vforvikash
In that case I'll have to make a bunch of interceptor. I suppose the answer is somewhere in ribbon where the host is resolved. I'll check more if I can do something like that. Thanks for your suggestion.
Comment From: grzegorzwitkowski
@vforvikash this is now possible in openfeign 10.6.0. Take a look here https://github.com/OpenFeign/feign/blob/10.6.0/core/src/main/java/feign/RequestTemplate.java
Now RequestTemplate attribute in RequestInterceptor has a new target field which has url and client name https://github.com/OpenFeign/feign/blob/10.6.0/core/src/main/java/feign/Target.java.
Comment From: vforvikash
@grzegorzwitkowski thanks for your response. Let me check how much framework i can update to get to that version.
Comment From: vforvikash
I'm using spring-cloud starter for openfeign...2.2.1 spring boot could get me feign 10.4.0. I am still stuck in the past. @grzegorzwitkowski
Comment From: vforvikash
@aaronjwhiteside finally i'm using your given solution instead of passing url with Header which is redundant. Thanks for your response.
Comment From: spencergibb
Feign was updated to 10.7.x here #270
Comment From: mattmadhavan
Hello @sdujanic , Could you please elaborate your points on "We are also using interceptors for AWS X-Ray call traces and since RequestTemplate does not provide full path our traces are not grouped. " ?
I am in the same situation of instrumenting OpenFeign calls - since we use openfeign for inter-service calls injunction with Service Discovery/Robbin etc!
Any insights will be appreciated!
Thanks Matt
Comment From: aaronjwhiteside
@mattmadhavan @sdujanic This may not be the answer you're looking for, but have you considered Spring Cloud Sleuth for tracing support, assumming of course that you're using Spring Boot?
There is also a Brave extension for AWS X-Ray intergration/propagation.
https://github.com/spring-cloud/spring-cloud-sleuth https://github.com/openzipkin/zipkin-aws/tree/master/brave-propagation-aws
Comment From: RadwaSaleh
@vforvikash this is now possible in openfeign 10.6.0. Take a look here https://github.com/OpenFeign/feign/blob/10.6.0/core/src/main/java/feign/RequestTemplate.java Now RequestTemplate attribute in RequestInterceptor has a new
targetfield which has url and client name https://github.com/OpenFeign/feign/blob/10.6.0/core/src/main/java/feign/Target.java.
This is to change the target but I'm unable to read the value