2727
2828import com .fasterxml .jackson .core .JsonProcessingException ;
2929import com .fasterxml .jackson .databind .DeserializationFeature ;
30+ import com .fasterxml .jackson .databind .MapperFeature ;
3031import com .fasterxml .jackson .databind .ObjectMapper ;
32+ import com .fasterxml .jackson .databind .json .JsonMapper ;
3133
3234import software .amazon .awssdk .http .SdkHttpClient ;
3335import software .amazon .awssdk .http .urlconnection .UrlConnectionHttpClient ;
4648 * Class in charge of retrieving the actual traces of a Lambda execution on X-Ray
4749 */
4850public 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