Skip to content

Commit fbfd0af

Browse files
authored
chore(maintenance): switch to unmanaged log group for functions (#3014)
1 parent abe27ab commit fbfd0af

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

packages/testing/src/resources/TestNodejsFunction.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { randomUUID } from 'node:crypto';
22
import { CfnOutput, Duration } from 'aws-cdk-lib';
33
import { Tracing } from 'aws-cdk-lib/aws-lambda';
44
import { NodejsFunction, OutputFormat } from 'aws-cdk-lib/aws-lambda-nodejs';
5-
import { RetentionDays } from 'aws-cdk-lib/aws-logs';
5+
import { LogGroup, RetentionDays } from 'aws-cdk-lib/aws-logs';
66
import type { TestStack } from '../TestStack.js';
77
import { TEST_ARCHITECTURES, TEST_RUNTIMES } from '../constants.js';
88
import {
@@ -25,8 +25,17 @@ class TestNodejsFunction extends NodejsFunction {
2525
) {
2626
const isESM = extraProps.outputFormat === 'ESM';
2727
const { bundling, ...restProps } = props;
28+
const functionName = concatenateResourceName({
29+
testName: stack.testName,
30+
resourceName: extraProps.nameSuffix,
31+
});
32+
const resourceId = randomUUID().substring(0, 5);
2833

29-
super(stack.stack, `fn-${randomUUID().substring(0, 5)}`, {
34+
const logGroup = new LogGroup(stack.stack, `log-${resourceId}`, {
35+
logGroupName: `/aws/lambda/${functionName}`,
36+
retention: RetentionDays.ONE_DAY,
37+
});
38+
super(stack.stack, `fn-${resourceId}`, {
3039
timeout: Duration.seconds(30),
3140
memorySize: 512,
3241
tracing: Tracing.ACTIVE,
@@ -41,13 +50,10 @@ class TestNodejsFunction extends NodejsFunction {
4150
: '',
4251
},
4352
...restProps,
44-
functionName: concatenateResourceName({
45-
testName: stack.testName,
46-
resourceName: extraProps.nameSuffix,
47-
}),
53+
functionName,
4854
runtime: TEST_RUNTIMES[getRuntimeKey()],
4955
architecture: TEST_ARCHITECTURES[getArchitectureKey()],
50-
logRetention: RetentionDays.ONE_DAY,
56+
logGroup,
5157
});
5258

5359
new CfnOutput(this, extraProps.nameSuffix, {

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

Lines changed: 2 additions & 3 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(
@@ -342,7 +341,7 @@ const getTraces = async (
342341

343342
const { resourceName } = options;
344343

345-
const mainSubsegments = [];
344+
const mainSubsegments: EnrichedXRayTraceDocumentParsed[] = [];
346345
for (const trace of traces) {
347346
const mainSubsegment = findPowertoolsFunctionSegment(trace, resourceName);
348347
const enrichedMainSubsegment = {

0 commit comments

Comments
 (0)