Skip to content

Commit 0d52313

Browse files
committed
Add retries for trace subsegments as well.
1 parent 71fd5f0 commit 0d52313

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

powertools-e2e-tests/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@
150150
<version>2.4</version>
151151
<scope>test</scope>
152152
</dependency>
153+
<dependency>
154+
<groupId>com.fasterxml.jackson.core</groupId>
155+
<artifactId>jackson-databind</artifactId>
156+
<scope>test</scope>
157+
</dependency>
158+
<dependency>
159+
<groupId>com.fasterxml.jackson.datatype</groupId>
160+
<artifactId>jackson-datatype-jsr310</artifactId>
161+
<scope>test</scope>
162+
</dependency>
153163
<dependency>
154164
<groupId>org.aspectj</groupId>
155165
<artifactId>aspectjrt</artifactId>

powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/tracing/TraceFetcher.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727

2828
import com.fasterxml.jackson.core.JsonProcessingException;
2929
import com.fasterxml.jackson.databind.DeserializationFeature;
30+
import com.fasterxml.jackson.databind.MapperFeature;
3031
import com.fasterxml.jackson.databind.ObjectMapper;
32+
import com.fasterxml.jackson.databind.json.JsonMapper;
3133

3234
import software.amazon.awssdk.http.SdkHttpClient;
3335
import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient;
@@ -46,9 +48,10 @@
4648
* Class in charge of retrieving the actual traces of a Lambda execution on X-Ray
4749
*/
4850
public class TraceFetcher {
49-
50-
private static final ObjectMapper MAPPER = new ObjectMapper()
51-
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
51+
private static final ObjectMapper MAPPER = JsonMapper.builder()
52+
.disable(MapperFeature.REQUIRE_HANDLERS_FOR_JAVA8_TIMES)
53+
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
54+
.build();
5255
private static final Logger LOG = LoggerFactory.getLogger(TraceFetcher.class);
5356
private static final SdkHttpClient httpClient = UrlConnectionHttpClient.builder().build();
5457
private static final Region region = Region.of(System.getProperty("AWS_DEFAULT_REGION", "eu-west-1"));
@@ -104,7 +107,7 @@ private Trace getTrace(List<String> traceIds) {
104107
.traceIds(traceIds)
105108
.build());
106109
if (!tracesResponse.hasTraces()) {
107-
throw new TraceNotFoundException("No trace found");
110+
throw new TraceNotFoundException(String.format("No trace found for traceIds %s", traceIds));
108111
}
109112
Trace traceRes = new Trace();
110113
tracesResponse.traces().forEach(trace -> {
@@ -113,15 +116,21 @@ private Trace getTrace(List<String> traceIds) {
113116
try {
114117
SegmentDocument document = MAPPER.readValue(segment.document(), SegmentDocument.class);
115118
if ("AWS::Lambda::Function".equals(document.getOrigin()) && document.hasSubsegments()) {
116-
getNestedSubSegments(document.getSubsegments(), traceRes,
117-
Collections.emptyList());
119+
getNestedSubSegments(document.getSubsegments(), traceRes, Collections.emptyList());
120+
} else if ("AWS::Lambda::Function".equals(document.getOrigin())) {
121+
LOG.debug(
122+
"Found AWS::Lambda::Function SegmentDocument with no subsegments. Retrying {}",
123+
MAPPER.writeValueAsString(document));
124+
throw new TraceNotFoundException(
125+
"Found AWS::Lambda::Function SegmentDocument with no subsegments.");
118126
}
119-
120127
} catch (JsonProcessingException e) {
121128
LOG.error("Failed to parse segment document: " + e.getMessage());
122129
throw new RuntimeException(e);
123130
}
124131
});
132+
} else {
133+
throw new TraceNotFoundException(String.format("No segments found in trace %s", trace.id()));
125134
}
126135
});
127136
return traceRes;

0 commit comments

Comments
 (0)