docs(metrics): document InvokeStore isolation and local testing#5486
docs(metrics): document InvokeStore isolation and local testing#5486leiwilson wants to merge 2 commits into
Conversation
|
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
|
|
||
| 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. |
There was a problem hiding this comment.
It's not just local runs and unit tests, it's the default behaviour in a standard lambda function too.
|
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. |
|
Thanks. The acknowledgment is in the description and the Acknowledgment Check is passing. |
|
Can you address this comment too: #5486 (comment). Just needs a slight wording change to make the text clearer. |
|
Thanks. Updated the wording so the in-memory store is described as the default on standard Lambda too, not only for local/tests. |
Summary
Documents how Metrics behaves in the Lambda environment versus locally, including automatic per-invocation isolation via
@aws/lambda-invoke-storewhen 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
MetricsStore/shouldUseInvokeStoreDocs-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.