Skip to content

Commit 32d2f08

Browse files
committed
chore(testing): use retry options in xray trace retrieval
1 parent a65cee5 commit 32d2f08

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

packages/testing/src/xray-traces-utils.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ const getTraceIds = async (
4949
);
5050
}
5151

52-
const ids = [];
53-
52+
const ids: string[] = [];
5453
for (const summary of summaries) {
5554
if (summary.Id === undefined) {
5655
throw new Error(
@@ -83,10 +82,15 @@ const retriableGetTraceIds = (options: GetXRayTraceIdsOptions) =>
8382
endTime.getTime() / 1000
8483
)} --filter-expression 'resource.arn ENDSWITH ":function:${options.resourceName}"'`
8584
);
85+
86+
throw new Error(
87+
`Failed to get trace IDs for ${options.resourceName} after ${retryOptions.retries} retries`,
88+
{ cause: error }
89+
);
8690
}
8791
retry(error);
8892
}
89-
});
93+
}, retryOptions);
9094

9195
/**
9296
* Parse and sort the trace segments by start time
@@ -168,13 +172,25 @@ const getTraceDetails = async (
168172
* @param options - The options to get trace details, including the trace IDs and expected segments count
169173
*/
170174
const retriableGetTraceDetails = (options: GetXRayTraceDetailsOptions) =>
171-
promiseRetry(async (retry) => {
175+
promiseRetry(async (retry, attempt) => {
172176
try {
173177
return await getTraceDetails(options);
174178
} catch (error) {
179+
if (attempt === retryOptions.retries) {
180+
console.log(
181+
`Manual query: aws xray get-trace-summaries --start-time ${
182+
options.traceIds
183+
}`
184+
);
185+
186+
throw new Error(
187+
`Failed to get trace details for ${options.traceIds} after ${retryOptions.retries} retries`,
188+
{ cause: error }
189+
);
190+
}
175191
retry(error);
176192
}
177-
});
193+
}, retryOptions);
178194

179195
/**
180196
* Find the main function segment in the trace identified by the `## index.` suffix
@@ -292,7 +308,7 @@ const getTraces = async (
292308

293309
const { resourceName } = options;
294310

295-
const mainSubsegments = [];
311+
const mainSubsegments: EnrichedXRayTraceDocumentParsed[] = [];
296312
for (const trace of traces) {
297313
const mainSubsegment = findPowertoolsFunctionSegment(trace, resourceName);
298314
const enrichedMainSubsegment = {
@@ -319,7 +335,7 @@ const getTracesWithoutMainSubsegments = async (
319335

320336
const { resourceName } = options;
321337

322-
const lambdaFunctionSegments = [];
338+
const lambdaFunctionSegments: EnrichedXRayTraceDocumentParsed[] = [];
323339
for (const trace of traces) {
324340
const functionSegment = trace.Segments.find(
325341
(segment) => segment.Document.origin === 'AWS::Lambda::Function'

0 commit comments

Comments
 (0)