Skip to content

Commit 4f613fe

Browse files
committed
test(tracer): streamline e2e test cases
1 parent 23a33dc commit 4f613fe

19 files changed

+611
-1489
lines changed

package-lock.json

Lines changed: 1 addition & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/testing/src/types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,13 @@ type XRayTraceDocumentParsed = {
108108
request_id: string;
109109
};
110110
http?: {
111-
response: {
111+
request: {
112+
url: string;
113+
method: string;
114+
};
115+
response?: {
112116
status: number;
117+
content_length?: number;
113118
};
114119
};
115120
origin?: string;
@@ -142,6 +147,7 @@ type XRayTraceDocumentParsed = {
142147
message: string;
143148
};
144149
error?: boolean;
150+
namespace?: string;
145151
};
146152

147153
type XRaySegmentParsed = {

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

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,15 @@ const retriableGetTraceIds = (options: GetXRayTraceIdsOptions) =>
8383
endTime.getTime() / 1000
8484
)} --filter-expression 'resource.arn ENDSWITH ":function:${options.resourceName}"'`
8585
);
86+
87+
throw new Error(
88+
`Failed to get trace IDs after ${retryOptions.retries} retries`,
89+
{ cause: error }
90+
);
8691
}
8792
retry(error);
8893
}
89-
});
94+
}, retryOptions);
9095

9196
/**
9297
* Parse and sort the trace segments by start time
@@ -168,13 +173,25 @@ const getTraceDetails = async (
168173
* @param options - The options to get trace details, including the trace IDs and expected segments count
169174
*/
170175
const retriableGetTraceDetails = (options: GetXRayTraceDetailsOptions) =>
171-
promiseRetry(async (retry) => {
176+
promiseRetry(async (retry, attempt) => {
172177
try {
173178
return await getTraceDetails(options);
174179
} catch (error) {
180+
if (attempt === retryOptions.retries) {
181+
console.log(
182+
`Manual query: aws xray batch-get-traces --trace-ids ${
183+
options.traceIds
184+
}`
185+
);
186+
187+
throw new Error(
188+
`Failed to get trace details after ${retryOptions.retries} retries`,
189+
{ cause: error }
190+
);
191+
}
175192
retry(error);
176193
}
177-
});
194+
}, retryOptions);
178195

179196
/**
180197
* Find the main function segment in the trace identified by the `## index.` suffix
@@ -305,45 +322,6 @@ const getTraces = async (
305322
return mainSubsegments;
306323
};
307324

308-
/**
309-
* Get the X-Ray trace data for a given resource name without the main subsegments.
310-
*
311-
* This is useful when we are testing cases where Active Tracing is disabled and we don't have the main subsegments.
312-
*
313-
* @param options - The options to get the X-Ray trace data, including the start time, resource name, expected traces count, and expected segments count
314-
*/
315-
const getTracesWithoutMainSubsegments = async (
316-
options: GetXRayTraceIdsOptions & Omit<GetXRayTraceDetailsOptions, 'traceIds'>
317-
): Promise<EnrichedXRayTraceDocumentParsed[]> => {
318-
const traces = await getXRayTraceData(options);
319-
320-
const { resourceName } = options;
321-
322-
const lambdaFunctionSegments = [];
323-
for (const trace of traces) {
324-
const functionSegment = trace.Segments.find(
325-
(segment) => segment.Document.origin === 'AWS::Lambda::Function'
326-
);
327-
328-
if (!functionSegment) {
329-
throw new Error(
330-
`AWS::Lambda::Function segment not found for ${resourceName}`
331-
);
332-
}
333-
334-
const lambdaFunctionSegment = functionSegment.Document;
335-
const enrichedSubsegment = {
336-
...lambdaFunctionSegment,
337-
subsegments: parseSubsegmentsByName(
338-
lambdaFunctionSegment.subsegments ?? []
339-
),
340-
};
341-
lambdaFunctionSegments.push(enrichedSubsegment);
342-
}
343-
344-
return lambdaFunctionSegments;
345-
};
346-
347325
export {
348326
getTraceIds,
349327
retriableGetTraceIds,
@@ -352,5 +330,4 @@ export {
352330
findPowertoolsFunctionSegment,
353331
getTraces,
354332
parseSubsegmentsByName,
355-
getTracesWithoutMainSubsegments,
356333
};

packages/tracer/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
"devDependencies": {
3030
"@aws-lambda-powertools/testing-utils": "file:../testing",
3131
"@aws-sdk/client-dynamodb": "^3.637.0",
32-
"@aws-sdk/client-xray": "^3.637.0",
33-
"aws-sdk": "^2.1688.0"
32+
"@aws-sdk/client-xray": "^3.637.0"
3433
},
3534
"peerDependencies": {
3635
"@middy/core": "4.x || 5.x"

packages/tracer/tests/e2e/allFeatures.decorator.test.functionCode.ts

Lines changed: 0 additions & 121 deletions
This file was deleted.

0 commit comments

Comments
 (0)