5

I have a web application (spring) which I want to instrument using AWS-XRay. I have added "AWSXRayServletFilter" in my web.xml, and the below snippet in my spring configuration class, as per documentation.

static {
    AWSXRayRecorderBuilder builder = AWSXRayRecorderBuilder.standard()
        .withPlugin(new EC2Plugin()).withPlugin(new ECSPlugin());

    builder.withSamplingStrategy(new DefaultSamplingStrategy());

    AWSXRay.setGlobalRecorder(builder.build());
}

The below dependency is also added in pom.xml

<dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-xray-recorder-sdk-aws-sdk-instrumentor</artifactId>
            <version>1.2.0</version>
</dependency>

During the application start up, I am getting the below exception.

com.amazonaws.xray.exceptions.SegmentNotFoundException: Failed to begin subsegment named 'AmazonDynamoDBv2': segment cannot be found

Any pointers to solve this will be helpful

Anil Bhaskaran
  • 495
  • 1
  • 8
  • 23

2 Answers2

6

When you init the global recorder, you should also start the parent segment. You're trying to create a SubSegment, without a Segment.

AWSXRay.setGlobalRecorder(AWSXRayRecorderBuilder.defaultRecorder());
AWSXRay.beginSegment("MySeg");
3

I only got this in junit-tests where dynamodb was mocked. To fix I put

AWSXRay.beginSegment("AmazonDynamoDBv2");

in test setup (@Before)

I did not touch implementation since I believe this is something Amazon already does in its SDK?

Peter
  • 5,556
  • 3
  • 23
  • 38