首页 > 解决方案 > Cognito xray - segment not found issue

问题描述

I am trying to use x-ray with cognito:

val client: AWSCognitoIdentityProvider =
    AWSCognitoIdentityProviderClientBuilder
      .standard()
      .withCredentials(keysConfig.credentialsProvider)
      .withRegion(config.region)
      .withClientConfiguration(new ClientConfiguration().withMaxErrorRetry(config.maxErrorRetries))
      .withRequestHandlers(new TracingHandler(AWSXRay.getGlobalRecorder))
      .build()

but I get bunch of errors:

SEVERE: Suppressing AWS X-Ray context missing exception (SegmentNotFoundException): Failed to begin subsegment named 'AWSCognitoIdentityProvider': segment cannot be found

I am doing it by an example from:

https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-java-awssdkclients.html[https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-java-awssdkclients.html][1]

should I do some extra configuration in the aws xray UI ?

EDIT: I tried also to remove manually adding request handler and just add a dependency: aws-xray-recorder-sdk-aws-sdk-instrumentor but the same issue..

标签: javaamazon-web-servicesscalaaws-xray

解决方案


启用 AWS 开发工具包工具将自动subSegment为您的 AWS 调用生成。但在 AWS Xray 中,subSegment 必须在现有父级之下,segment否则将获得 SegmentNotFoundException。

您能否尝试使用 beginSegment() 和 endSegment() 包装您的 AWS 调用?

import com.amazonaws.xray.AWSXRay;
import com.amazonaws.xray.entities.Segment;

try {
    segment = AWSXRay.beginSegment("your service name");
    // your AWS call
    AWSCognito.xxx
} catch (Exception e) {
    throw e;
} finally {
    AWSXRay.endSegment();
}

推荐阅读