|
31 | 31 | import com.amazonaws.services.xray.model.Segment;
|
32 | 32 | import com.amazonaws.services.xray.model.Trace;
|
33 | 33 | import com.amazonaws.services.xray.model.TraceSummary;
|
34 |
| -import com.amazonaws.services.xray.model.ValueWithServiceIds; |
35 | 34 | import com.fasterxml.jackson.core.JsonProcessingException;
|
36 | 35 | import com.fasterxml.jackson.databind.ObjectMapper;
|
37 | 36 | import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
@@ -133,35 +132,13 @@ public void validate() throws Exception {
|
133 | 132 | private Map<String, Object> getRetrievedTrace(List<String> traceIdList) throws Exception {
|
134 | 133 | List<Trace> retrieveTraceList = null;
|
135 | 134 | // Special Case for the /client-call. The API call doesn't return the trace ID of the local root
|
136 |
| - // client span, |
137 |
| - // so find traces generated within the last 60 second and search for the InternalOperation |
138 |
| - // Keyword. |
| 135 | + // client span, so find the trace by filtering traces generated within the last 60 second |
| 136 | + // with the serviceName and the local_root_client_call keyword. |
139 | 137 | if (XRayService.DEFAULT_TRACE_ID.equals(traceIdList.get(0))) {
|
140 |
| - List<TraceSummary> retrieveTraceLists = xrayService.searchTraces(); |
141 |
| - for (TraceSummary summary : retrieveTraceLists) { |
142 |
| - try { |
143 |
| - boolean isClientCall = false; |
144 |
| - // A summary represents a trace. The trace for the local-root-client-call will have two |
145 |
| - // segments, each with their own aws_local_service key in the annotation section. |
146 |
| - // Therefore, |
147 |
| - // getAnnotations.get("aws_local_service") will return a list with two values, one from |
148 |
| - // each segment. Search in the list to find whether local-root-client-call exists. |
149 |
| - for (ValueWithServiceIds service : summary.getAnnotations().get("aws_local_service")) { |
150 |
| - if (service.getAnnotationValue().getStringValue().equals("local-root-client-call")) { |
151 |
| - isClientCall = true; |
152 |
| - break; |
153 |
| - } |
154 |
| - } |
155 |
| - |
156 |
| - if (isClientCall) { |
157 |
| - List<String> traceIdLists = Collections.singletonList(summary.getId()); |
158 |
| - retrieveTraceList = xrayService.listTraceByIds(traceIdLists); |
159 |
| - break; |
160 |
| - } |
161 |
| - } catch (Exception e) { |
162 |
| - // Keep iterating until the right trace is found |
163 |
| - } |
164 |
| - } |
| 138 | + List<TraceSummary> retrieveTraceLists = |
| 139 | + xrayService.searchClientCallTraces(context.getServiceName()); |
| 140 | + List<String> traceIdLists = Collections.singletonList(retrieveTraceLists.get(0).getId()); |
| 141 | + retrieveTraceList = xrayService.listTraceByIds(traceIdLists); |
165 | 142 | } else {
|
166 | 143 | retrieveTraceList = xrayService.listTraceByIds(traceIdList);
|
167 | 144 | }
|
|
0 commit comments