generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 176
Closed as not planned
Labels
not-a-bugNew and existing bug reports incorrectly submitted as bugNew and existing bug reports incorrectly submitted as bug
Description
Expected Behavior
From reading the docs: https://docs.aws.amazon.com/powertools/typescript/latest/features/metrics/#testing-your-code setting POWERTOOLS_DEV env var as true should suppress any console logs
Current Behavior
However still the unit tests output this:
No application metrics to publish. The cold-start metric may be published if enabled. If application metrics should never be empty, consider using `throwOnEmptyMetrics
Code snippet
Using latest version 4 of Vitest, but also tried on v3 with same issue.
This example just sets the env var in the specific test, but also tried it in a beforeAll block and even in a setup tests file configured as part of the vitest config.
it('should not log about no application metrics to publish', async () => {
process.env.POWERTOOLS_DEV = 'true';
const metrics = new Metrics();
const mainHandler: ConnectContactFlowHandler = async (event: ConnectContactFlowEvent) => {
return await Promise.resolve({
eventName: event.Name,
result: 'hello',
});
};
const mockContext: Context = {
awsRequestId: '',
callbackWaitsForEmptyEventLoop: true,
done: () => 1,
fail: () => 1,
functionName: 'handler',
functionVersion: '1',
getRemainingTimeInMillis: () => 1,
invokedFunctionArn: '',
logGroupName: '',
logStreamName: '',
memoryLimitInMB: '512',
succeed: () => 1,
};
const mockConnectContactFlowEvent: ConnectContactFlowEvent = {
Details: {
ContactData: {
Attributes: {
attr: '1234',
},
Channel: 'CHAT',
ContactId: '123',
CustomerEndpoint: null,
InitialContactId: '',
InitiationMethod: 'INBOUND',
InstanceARN: '',
MediaStreams: {
Customer: {
Audio: null,
},
},
PreviousContactId: '',
Queue: null,
SystemEndpoint: null,
},
Parameters: {},
},
Name: 'ContactFlowEvent',
};
await middy(mainHandler).use(logMetrics(metrics))(mockConnectContactFlowEvent, mockContext);
expect(metrics.hasStoredMetrics()).toBe(false);
});Steps to Reproduce
Node22, Vitest 3 or 4
Run a unit test on a lambda wrapped with middy and logMetrics middleware
Console logs when no metrics were published, even with the environment variable set to true
Possible Solution
No response
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
22.x
Packaging format used
npm
Execution logs
Metadata
Metadata
Assignees
Labels
not-a-bugNew and existing bug reports incorrectly submitted as bugNew and existing bug reports incorrectly submitted as bug
Type
Projects
Status
Closed