Lambda Powertools Java - SegmentNotFound - @Tracing

Viewed 95

Just added Lambda Powertools Java to my project and I have annotated my handler method with @Tracing.

However now when I run my basic unit tests I get an error "SegmentNotFound". I think I may be able to create a segment in a test like AWSXRay.beginSegment("handleRequest") but not sure that is what I should be doing.

TIA

1 Answers

The powertools docs have now been updated explaining this here.

Essentially you do need beginSegment and this can be achieved in a couple of different ways. You can avoid the noise by putting:

<!--  Configures environment variable to avoid initialization of AWS X-Ray segments for each tests-->
      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <configuration>
              <environmentVariables>
                  <LAMBDA_TASK_ROOT>handler</LAMBDA_TASK_ROOT>
              </environmentVariables>
          </configuration>
      </plugin>

...in your pom.

Related