diff --git a/powertools-metrics/src/main/java/software/amazon/lambda/powertools/metrics/MetricsUtils.java b/powertools-metrics/src/main/java/software/amazon/lambda/powertools/metrics/MetricsUtils.java
index 8e28071dd..6c3a89a65 100644
--- a/powertools-metrics/src/main/java/software/amazon/lambda/powertools/metrics/MetricsUtils.java
+++ b/powertools-metrics/src/main/java/software/amazon/lambda/powertools/metrics/MetricsUtils.java
@@ -14,7 +14,6 @@
package software.amazon.lambda.powertools.metrics;
-import static java.util.Objects.requireNonNull;
import static java.util.Optional.ofNullable;
import static software.amazon.lambda.powertools.common.internal.LambdaHandlerProcessor.getXrayTraceId;
import static software.amazon.lambda.powertools.metrics.internal.LambdaMetricsAspect.REQUEST_ID_PROPERTY;
diff --git a/powertools-tracing/pom.xml b/powertools-tracing/pom.xml
index 9d60d4f40..345f14194 100644
--- a/powertools-tracing/pom.xml
+++ b/powertools-tracing/pom.xml
@@ -78,6 +78,11 @@
junit-jupiter-engine
test
+
+ org.junit-pioneer
+ junit-pioneer
+ test
+
org.apache.commons
commons-lang3
diff --git a/powertools-tracing/src/test/java/software/amazon/lambda/powertools/tracing/internal/LambdaTracingAspectTest.java b/powertools-tracing/src/test/java/software/amazon/lambda/powertools/tracing/internal/LambdaTracingAspectTest.java
index f070349d7..4aefdec9c 100644
--- a/powertools-tracing/src/test/java/software/amazon/lambda/powertools/tracing/internal/LambdaTracingAspectTest.java
+++ b/powertools-tracing/src/test/java/software/amazon/lambda/powertools/tracing/internal/LambdaTracingAspectTest.java
@@ -33,6 +33,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junitpioneer.jupiter.SetEnvironmentVariable;
import org.mockito.Mock;
import org.mockito.MockedStatic;
import software.amazon.lambda.powertools.common.internal.LambdaHandlerProcessor;
@@ -113,6 +114,28 @@ void shouldCaptureNonHandlerMethodWithCustomSegmentName() {
void shouldCaptureTraces() {
requestHandler.handleRequest(new Object(), context);
+ assertThat(AWSXRay.getTraceEntity())
+ .isNotNull();
+
+ assertThat(AWSXRay.getTraceEntity().getSubsegmentsCopy())
+ .hasSize(1)
+ .allSatisfy(subsegment ->
+ {
+ assertThat(subsegment.getAnnotations())
+ .hasSize(2)
+ .containsEntry("ColdStart", true)
+ .containsEntry("Service", "lambdaHandler");
+
+ assertThat(subsegment.getMetadata())
+ .hasSize(0);
+ });
+ }
+
+ @Test
+ @SetEnvironmentVariable(key = "POWERTOOLS_TRACER_CAPTURE_RESPONSE", value = "true")
+ void shouldCaptureTracesWithResponseMetadata() {
+ requestHandler.handleRequest(new Object(), context);
+
assertThat(AWSXRay.getTraceEntity())
.isNotNull();
@@ -132,6 +155,7 @@ void shouldCaptureTraces() {
}
@Test
+ @SetEnvironmentVariable(key = "POWERTOOLS_TRACER_CAPTURE_ERROR", value = "true")
void shouldCaptureTracesWithExceptionMetaData() {
requestHandler = new PowerTracerToolEnabledWithException();
@@ -163,6 +187,25 @@ void shouldCaptureTracesWithExceptionMetaData() {
void shouldCaptureTracesForStream() throws IOException {
streamHandler.handleRequest(new ByteArrayInputStream("test".getBytes()), new ByteArrayOutputStream(), context);
+ assertThat(AWSXRay.getTraceEntity())
+ .isNotNull();
+
+ assertThat(AWSXRay.getTraceEntity().getSubsegmentsCopy())
+ .hasSize(1)
+ .allSatisfy(subsegment ->
+ {
+ assertThat(subsegment.getAnnotations())
+ .hasSize(2)
+ .containsEntry("ColdStart", true)
+ .containsEntry("Service", "streamHandler");
+ });
+ }
+
+ @Test
+ @SetEnvironmentVariable(key = "POWERTOOLS_TRACER_CAPTURE_RESPONSE", value = "true")
+ void shouldCaptureTracesForStreamWithResponseMetadata() throws IOException {
+ streamHandler.handleRequest(new ByteArrayInputStream("test".getBytes()), new ByteArrayOutputStream(), context);
+
assertThat(AWSXRay.getTraceEntity())
.isNotNull();