AWS XRay wrong service map when using OpenFeign with AppMesh and AWS Service Discovery

505 views Asked by At

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

2

There are 2 answers

0
czetsuya On BEST ANSWER

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.

1
Nguyen Yen Vu On

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");
    }