Skip to content

Bug: POWERTOOLS_DEV as true does not seem to have any effect #4695

@ColinMorris83

Description

@ColinMorris83

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

No one assigned

    Labels

    not-a-bugNew and existing bug reports incorrectly submitted as bug

    Type

    No type

    Projects

    Status

    Closed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions