我们正在将 XRAY 添加到我们的 Spring Boot 应用程序中,但我无法解决以下错误:
Failed to begin subsegment named 'Amazon S3': segment cannot be found.
这是我们代码的相关部分:
pom.xml:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-xray-recorder-sdk-core</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-xray-recorder-sdk-aws-sdk</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-xray-recorder-sdk-aws-sdk-instrumentor</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-xray-recorder-sdk-apache-http</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-xray-recorder-sdk-spring</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-xray-recorder-sdk-sql-postgres</artifactId>
<version>1.2.1</version>
</dependency>
SpringApplication.java
@Bean
public Filter TracingFilter() {
return new AWSXRayServletFilter("myService");
}
类调用 S3
@PostConstruct
public void runOnStartup(){
String fileName = "myFileName";
String bucketName = "myBucketName";
amazonS3Client = AmazonS3ClientBuilder.standard()
.withCredentials(new ProfileCredentialsProvider("MyCredentials"))
.withClientConfiguration(getClientConfiguration())
.withRegion(region)
.build();
Segment segment = AWSXRay.beginSegment("do-startup-operation");
S3Object s3Object = amazonS3Client.getObject(bucketName, fileName);
AWSXRay.endSegment();
//Do stuff with S3Object
}
到目前为止我已经尝试过:
1)我已经尝试过使用和不使用 sdk-aws-sdk-instrumentor 导入,在这样做时添加 TracingHandler 配置,如本问题和本文档中所述。
.withRequestHandlers(new TracingHandler(AWSXRay.getGlobalRecorder()))
2) 我发现这个线程似乎建议使用 AWSXRAY.createSegment(),但我不确定 lambda 会发生什么,或者它是否与我的场景相关
我已阅读并发现相关的其他文档/代码: https ://docs.aws.amazon.com/xray/latest/devguide/scorekeep-startup.html
https://docs.aws.amazon.com/xray/latest/devguide/scorekeep-sdkclients.html
https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-java-multithreading.html
https://docs.aws.amazon.com/xray/latest/devguide/scorekeep-workerthreads.html
PS我简化了我的代码并省略了一些错误处理,以使查看此问题的人更容易阅读