From ba58b50f7ff18fda2784ce85ab78bd8cad15997b Mon Sep 17 00:00:00 2001 From: Lei Wilson <305842734+leiwilson@users.noreply.github.com> Date: Mon, 20 Jul 2026 17:19:03 +0100 Subject: [PATCH 1/3] docs(metrics): document InvokeStore isolation and local testing --- docs/features/metrics.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/features/metrics.md b/docs/features/metrics.md index cb0540cda9..6943fee7d6 100644 --- a/docs/features/metrics.md +++ b/docs/features/metrics.md @@ -456,6 +456,16 @@ You can customize how Metrics logs warnings and debug messages to standard outpu ## Testing your code +### Lambda environment vs local + +In AWS Lambda, Metrics writes [Embedded Metric Format (EMF)](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format.html) blobs to standard output. The Lambda runtime/CloudWatch agent picks those log lines up — you do not call CloudWatch `PutMetricData` yourself. + +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. + +### Asserting metrics in unit tests + When unit testing your code that uses the Metrics utility, you may want to silence the logs emitted by the utility. To do so, you can set the `POWERTOOLS_DEV` environment variable to `true`. This instructs the utility to not emit any logs to standard output. If instead you want to spy on the logs emitted by the utility, you must set the `POWERTOOLS_DEV` environment variable to `true` in conjunction with the `POWERTOOLS_METRICS_DISABLED` environment variable set to `false`. From cfdaabafa2a3f0a6d42dbc6958d5ce4b1ff23c87 Mon Sep 17 00:00:00 2001 From: Lei Wilson <305842734+leiwilson@users.noreply.github.com> Date: Wed, 22 Jul 2026 21:09:01 +0100 Subject: [PATCH 2/3] docs(metrics): clarify in-memory store is default on Lambda --- docs/features/metrics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/features/metrics.md b/docs/features/metrics.md index 6943fee7d6..aa3f3c5497 100644 --- a/docs/features/metrics.md +++ b/docs/features/metrics.md @@ -462,7 +462,7 @@ In AWS Lambda, Metrics writes [Embedded Metric Format (EMF)](https://docs.aws.am 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. +Outside that Lambda multi-concurrency context Metrics uses an in-memory store by default. That applies to standard Lambda functions, local runs and unit tests. Buffered metrics are still flushed as EMF to stdout when you flush (middleware/decorator/`logMetrics`), so asserting emitted metrics locally works the same way. ### Asserting metrics in unit tests From 693c6b5782cdda15bc2f050589bb69b8eadfd870 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Thu, 23 Jul 2026 17:47:01 +0200 Subject: [PATCH 3/3] chore: address comment Co-authored-by: Stefano Vozza --- docs/features/metrics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/features/metrics.md b/docs/features/metrics.md index aa3f3c5497..5e50ad3a65 100644 --- a/docs/features/metrics.md +++ b/docs/features/metrics.md @@ -462,7 +462,7 @@ In AWS Lambda, Metrics writes [Embedded Metric Format (EMF)](https://docs.aws.am 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 Metrics uses an in-memory store by default. That applies to standard Lambda functions, local runs and unit tests. Buffered metrics are still flushed as EMF to stdout when you flush (middleware/decorator/`logMetrics`), so asserting emitted metrics locally works the same way. +Outside that Lambda multi-concurrency context Metrics uses an in-memory store by default. This applies to Lambda on-demand functions, local runs, and unit tests. Buffered metrics are still flushed as EMF to stdout when you flush (middleware/decorator/`logMetrics`), so asserting emitted metrics locally works the same way. ### Asserting metrics in unit tests