将 OpenFeign 与 AppMesh 和 AWS Service Discovery 结合使用时,AWS XRay 服务映射错误

发布于 2025-01-16 00:01:39 字数 831 浏览 1 评论 0原文

我正在测试与部署在 AWS 上且启用了 AppMesh 和服务发现的 Spring Boot Rest 服务的服务间通信。为了能够从服务 a 向服务 b 发送消息,我必须使用 OpenFeign 客户端生成代理类。

技术堆栈

  • Spring Boot OpenFeign
  • AWS XRay
  • ECS
  • ECR
  • Sleuth
  • AppMesh(虚拟节点、虚拟服务)
  • AWS 服务发现(而不是 Eureka)

预期行为

在 AWS XRay 中,它应该显示调用跟踪:

客户端->服务A-> ServiceB

实际行为

在AWS XRay中,我可以看到调用跟踪:

Client ->服务A 客户-> ServiceB

是如何告诉 OpenFeign 使用 AWS SDK 中的 HttpClient?

其他信息

存储库位于:https://github.com /czetsuya/lab-microservice-spring-aws

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奈何桥上唱咆哮 2025-01-23 00:01:39

不确定您是否已经找到解决方案,下面的代码片段可以帮助您:

首先,您需要使用 Feign Http Client:

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

创建使用 aws xray 中的 apache http 客户端的 Feign Builder


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

初始化您的客户端:

@Bean
    CallingService TestSnsPushNotificationApis(@Autowired Feign.Builder builder) {
        return builder.target(CallingService.class, "http://localhost:8081");
    }

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");
    }
栀梦 2025-01-23 00:01:39

我能够通过在tracingFilter中使用dynamicNamingStrategy

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

并创建一个HttpClientBuilder bean来解决这个问题。

@Bean
  public HttpClientBuilder xrayHttpClientBuilder() {

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

AWS XRay 现在应该在跟踪中显示 HTTP 请求:
AWS XRay Trace

项目代码位于 https://github.com/czetsuya/lab-microservice-spring-aws

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文