Skip to content

Commit 3707b38

Browse files
committed
chore(testing): use retry options in xray trace retrieval
1 parent 23a33dc commit 3707b38

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

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

+21-7
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,14 @@ 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 after ${retryOptions.retries} attempts`
88+
);
8689
}
8790
retry(error);
8891
}
89-
});
92+
}, retryOptions);
9093

9194
/**
9295
* Parse and sort the trace segments by start time
@@ -168,13 +171,24 @@ const getTraceDetails = async (
168171
* @param options - The options to get trace details, including the trace IDs and expected segments count
169172
*/
170173
const retriableGetTraceDetails = (options: GetXRayTraceDetailsOptions) =>
171-
promiseRetry(async (retry) => {
174+
promiseRetry(async (retry, attempt) => {
172175
try {
173176
return await getTraceDetails(options);
174177
} catch (error) {
178+
if (attempt === retryOptions.retries) {
179+
console.log(
180+
`Manual query: aws xray batch-get-traces --trace-ids ${
181+
options.traceIds
182+
}`
183+
);
184+
185+
throw new Error(
186+
`Failed to get trace details after ${retryOptions.retries} attempts`
187+
);
188+
}
175189
retry(error);
176190
}
177-
});
191+
}, retryOptions);
178192

179193
/**
180194
* Find the main function segment in the trace identified by the `## index.` suffix
@@ -292,7 +306,7 @@ const getTraces = async (
292306

293307
const { resourceName } = options;
294308

295-
const mainSubsegments = [];
309+
const mainSubsegments: EnrichedXRayTraceDocumentParsed[] = [];
296310
for (const trace of traces) {
297311
const mainSubsegment = findPowertoolsFunctionSegment(trace, resourceName);
298312
const enrichedMainSubsegment = {
@@ -319,7 +333,7 @@ const getTracesWithoutMainSubsegments = async (
319333

320334
const { resourceName } = options;
321335

322-
const lambdaFunctionSegments = [];
336+
const lambdaFunctionSegments: EnrichedXRayTraceDocumentParsed[] = [];
323337
for (const trace of traces) {
324338
const functionSegment = trace.Segments.find(
325339
(segment) => segment.Document.origin === 'AWS::Lambda::Function'

0 commit comments

Comments
 (0)