首页 > 解决方案 > Lambda Powertools Java - SegmentNotFound - @Tracing

问题描述

刚刚将 Lambda Powertools Java 添加到我的项目中,我已经用@Tracing.

但是现在当我运行我的基本单元测试时,我收到一个错误“SegmentNotFound”。我想我可能能够在测试中创建一个片段,AWSXRay.beginSegment("handleRequest")但不确定这是我应该做的。

TIA

标签: amazon-web-servicesaws-lambda

解决方案


powertools 文档现已更新,在此处进行了解释。

本质上,您确实需要 beginSegment ,这可以通过几种不同的方式来实现。您可以通过以下方式避免噪音:

<!--  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>

...在你的 pom 中。


推荐阅读