AWS X-Ray AmazonDynamoDBv2 segment not found
Asked Answered
N

2

6

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

Notepaper answered 10/10, 2017 at 5:32 Comment(0)
E
7

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");
Ezequieleziechiele answered 26/10, 2017 at 18:42 Comment(0)
J
4

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?

Jorge answered 7/11, 2018 at 8:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.