From f81f02faf9014b8dd73d43a3345d5630ca740e12 Mon Sep 17 00:00:00 2001 From: Jose Villalobos Date: Tue, 22 Apr 2025 16:25:32 -0500 Subject: [PATCH 1/4] Docs: metrics.md file wrongly mentioned variable name to disable log Docs mentions POWERTOOLS_METRICS_ENABLED however the library does not uses this environment variable to control metrics logs. Instead it uses POWERTOOLS_METRICS_DISABLED --- 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 0954a7ec0e..daaccd0cd5 100644 --- a/docs/features/metrics.md +++ b/docs/features/metrics.md @@ -71,7 +71,7 @@ These settings will be used across all metrics emitted: | **Service** | Optionally, sets **service** metric dimension across all metrics | `POWERTOOLS_SERVICE_NAME` | `service_undefined` | Any string | `serverlessAirline` | `serviceName` | | **Metric namespace** | Logical container where all metrics will be placed | `POWERTOOLS_METRICS_NAMESPACE` | `default_namespace` | Any string | `serverlessAirline` | `default_namespace` | | **Function Name** | Function name used as dimension for the `ColdStart` metric | `POWERTOOLS_METRICS_FUNCTION_NAME` | [See docs](#capturing-a-cold-start-invocation-as-metric) | Any string | `my-function-name` | `functionName` | -| **Enabled** | Whether to emit metrics to standard output or not | `POWERTOOLS_METRICS_ENABLED` | `true` | Boolean | `false` | | +| **Disabled** | Whether to disable the log of metrics to standard output or not | `POWERTOOLS_METRICS_DISABLED` | `false` | Boolean | `true` | | !!! tip Use your application name or main service as the metric namespace to easily group all metrics From 41e5dc97a7b53376817d30a99e4bb784f130458b Mon Sep 17 00:00:00 2001 From: Jose Villalobos Date: Tue, 22 Apr 2025 17:15:03 -0500 Subject: [PATCH 2/4] Docs: Update metrics.md in all parts where POWERTOOLS_METRICS_ENABLED is mentioned --- 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 daaccd0cd5..add53e6bb1 100644 --- a/docs/features/metrics.md +++ b/docs/features/metrics.md @@ -493,7 +493,7 @@ You can customize how Metrics logs warnings and debug messages to standard outpu 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_ENABLED` environment variable also set to `true`. +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`. When `POWERTOOLS_DEV` is enabled, Metrics uses the global `console` to emit metrics to standard out. This allows you to easily spy on the logs emitted and make assertions on them. From c73329801a22de348e4561b1198832e8717f9997 Mon Sep 17 00:00:00 2001 From: Jose Villalobos Date: Tue, 22 Apr 2025 17:16:48 -0500 Subject: [PATCH 3/4] Update testingMetrics.ts example to use appropiate env variable name --- examples/snippets/metrics/testingMetrics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/snippets/metrics/testingMetrics.ts b/examples/snippets/metrics/testingMetrics.ts index af2d4b796c..dcf008fc07 100644 --- a/examples/snippets/metrics/testingMetrics.ts +++ b/examples/snippets/metrics/testingMetrics.ts @@ -2,7 +2,7 @@ import { describe, expect, it, vi } from 'vitest'; vi.hoisted(() => { process.env.POWERTOOLS_DEV = 'true'; - process.env.POWERTOOLS_METRICS_ENABLED = 'true'; + process.env.POWERTOOLS_METRICS_DISABLED = 'false'; }); describe('Metrics tests', () => { From 68495c5d5b7150f709b425c2b523a4bf9f3e9051 Mon Sep 17 00:00:00 2001 From: Jose Villalobos Date: Wed, 23 Apr 2025 09:15:51 -0500 Subject: [PATCH 4/4] docs: Update environment-variables.md Update environment-variables.md file to mention `POWERTOOLS_METRICS_DISABLED` environment variable instead of `POWERTOOLS_METRICS_ENABLED` --- docs/environment-variables.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/environment-variables.md b/docs/environment-variables.md index 66bf5fb52a..93d8596715 100644 --- a/docs/environment-variables.md +++ b/docs/environment-variables.md @@ -15,7 +15,7 @@ You can configure Powertools for AWS Lambda using environment variables. This is | **POWERTOOLS_SERVICE_NAME** | Set service name used for tracing namespace, metrics dimension and structured logging | All | `service_undefined` | | **POWERTOOLS_METRICS_NAMESPACE** | Set namespace used for metrics | [Metrics](features/metrics.md) | `default_namespace` | | **POWERTOOLS_METRICS_FUNCTION_NAME** | Function name used as dimension for the `ColdStart` metric | [Metrics](features/metrics.md) | [See docs](features/metrics.md#setting-function-name) | -| **POWERTOOLS_METRICS_ENABLED** | Explicitly disables emitting metrics to stdout | [Metrics](features/metrics.md) | `true` | +| **POWERTOOLS_METRICS_DISABLED** | Explicitly disables emitting metrics to stdout | [Metrics](features/metrics.md) | `false` | | **POWERTOOLS_TRACE_ENABLED** | Explicitly disables tracing | [Tracer](features/tracer.md) | `true` | | **POWERTOOLS_TRACER_CAPTURE_RESPONSE** | Capture Lambda or method return as metadata. | [Tracer](features/tracer.md) | `true` | | **POWERTOOLS_TRACER_CAPTURE_ERROR** | Capture Lambda or method exception as metadata. | [Tracer](features/tracer.md) | `true` | @@ -40,4 +40,4 @@ When `POWERTOOLS_DEV` is set to a truthy value (`1`, `true`), it'll have the fol | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | **Logger** | Increase JSON indentation to 4 and uses global `console` to emit logs to ease testing and local debugging when running functions locally. However, Amazon CloudWatch Logs view will degrade as each new line is treated as a new message | | **Tracer** | Disables tracing operations in non-Lambda environments. This already happens automatically in the Tracer utility | -| **Metrics** | Disables emitting metrics to stdout. Can be overridden by setting `POWERTOOLS_METRICS_ENABLED` to `true` | +| **Metrics** | Disables emitting metrics to stdout. Can be overridden by explicitly setting `POWERTOOLS_METRICS_DISABLED` to `false` |