1

I'm testing interservice communication with Spring Boot Rest services deployed on AWS with AppMesh and Service Discovery enabled. To be able to send messages from service a to service b I've to use the OpenFeign client to generate a proxy class.

Tech Stack

  • Spring Boot OpenFeign
  • AWS XRay
  • ECS
  • ECR
  • Sleuth
  • AppMesh (Virtual Node, Virtual Service)
  • AWS Service Discovery (instead of Eureka)

Expected Behavior

In AWS XRay, it should show a call trace:

Client -> ServiceA -> ServiceB

Actual Behavior

In AWS XRay, I can see the call traces:

Client -> ServiceA Client -> ServiceB

xray trace

Another question would be how to tell OpenFeign to use the HttpClient from AWS SDK?

Other Information

Repository available at: https://github.com/czetsuya/lab-microservice-spring-aws

czetsuya
  • 4,773
  • 13
  • 53
  • 99

2 Answers2

0

Not sure if you have found solution yet, the snippet code below could help you:

Firstly you need to use Feign Http Client:

implementation 'io.github.openfeign:feign-httpclient:9.5.0'

Create Feign Builder which use apache http client from aws xray


    @Bean
    public Feign.Builder feignBuilder() {
        //aws xray http client
        CloseableHttpClient client = HttpClientBuilder.create().build();
        return Feign.builder()
                .retryer(Retryer.NEVER_RETRY)
                .client(new ApacheHttpClient(client));
    }

Initialize your client:

@Bean
    CallingService TestSnsPushNotificationApis(@Autowired Feign.Builder builder) {
        return builder.target(CallingService.class, "http://localhost:8081");
    }
  • Hi. I'm using the FeignClient annotation on a proxy class https://github.com/czetsuya/lab-microservice-spring-aws/blob/main/job-services/src/main/java/com/czetsuyatech/jobs/web/controllers/ApplicantProxy.java. It should automatically use the FeignBuilder, unless there's an additional configuration that needs to be done? – czetsuya May 17 '22 at 08:52
0

I was able to fix this issue by using a dynamicNamingStrategy in tracingFilter

@Bean
  public Filter tracingFilter(final AWSXRayRecorder awsxRayRecorder) {

    log.info("Setting up AWS Xray tracing filter");
    return new AWSXRayServletFilter(SegmentNamingStrategy.dynamic(Optional.ofNullable(AWS_XRAY_SEGMENT_NAME).orElse(
        "xray-filter")));
  }

And create an HttpClientBuilder bean.

@Bean
  public HttpClientBuilder xrayHttpClientBuilder() {

    log.info("Setting up AWS xray http client configuration");
    return HttpClientBuilder.create();
  }

AWS XRay should now show the HTTP requests in the trace: AWS XRay Trace

The project code is available at https://github.com/czetsuya/lab-microservice-spring-aws.

czetsuya
  • 4,773
  • 13
  • 53
  • 99