Skip to content

docs(metrics): document InvokeStore isolation and local testing#5486

Open
leiwilson wants to merge 2 commits into
aws-powertools:mainfrom
leiwilson:docs/metrics-lambda-invoke-store-behavior
Open

docs(metrics): document InvokeStore isolation and local testing#5486
leiwilson wants to merge 2 commits into
aws-powertools:mainfrom
leiwilson:docs/metrics-lambda-invoke-store-behavior

Conversation

@leiwilson

@leiwilson leiwilson commented Jul 20, 2026

Copy link
Copy Markdown

Summary

Documents how Metrics behaves in the Lambda environment versus locally, including automatic per-invocation isolation via @aws/lambda-invoke-store when Lambda multi-concurrency is enabled, and clarifies how to assert emitted EMF metrics in unit tests.

Fixes #5187.

Changes

  • docs/features/metrics.md: add "Lambda environment vs local" and retitle the existing spy example under "Asserting metrics in unit tests"

Test plan

  • Skim Metrics docs Testing section for accuracy vs MetricsStore / shouldUseInvokeStore
  • Confirm existing testing snippet still renders

Docs-only; no AWS credentials required.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@boring-cyborg

boring-cyborg Bot commented Jul 20, 2026

Copy link
Copy Markdown

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #typescript channel on our Powertools for AWS Lambda Discord: Invite link

Comment thread docs/features/metrics.md Outdated

When Lambda multi-concurrency is enabled (`AWS_LAMBDA_MAX_CONCURRENCY` is set), Metrics (and related buffered state such as dimensions/metadata) automatically uses [`@aws/lambda-invoke-store`](https://www.npmjs.com/package/@aws/lambda-invoke-store) for **per-invocation isolation**. No application code changes are required; Powertools selects the store at runtime.

Outside that Lambda multi-concurrency context — including typical local runs and unit tests — Metrics uses an in-memory fallback store instead. Buffered metrics are still flushed as EMF to stdout when you flush (middleware/decorator/`logMetrics`), so local behavior for asserting emitted metrics remains the same.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not just local runs and unit tests, it's the default behaviour in a standard lambda function too.

@svozza

svozza commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Hi there, thanks for the contribution, can you add the acknowledgement section to the PR. You can see the wording in the GitHub template here: https://github.com/aws-powertools/powertools-lambda-typescript/blob/main/.github/PULL_REQUEST_TEMPLATE.md.

@leiwilson

Copy link
Copy Markdown
Author

Thanks. The acknowledgment is in the description and the Acknowledgment Check is passing.

@svozza

svozza commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Can you address this comment too: #5486 (comment). Just needs a slight wording change to make the text clearer.

@leiwilson

Copy link
Copy Markdown
Author

Thanks. Updated the wording so the in-memory store is described as the default on standard Lambda too, not only for local/tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S PR between 10-29 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs: Powertools Metrics behavior in Lambda environment

2 participants