You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/logger.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -111,7 +111,7 @@ This functionality will include the following keys in your structured logs:
111
111
=== "Middy Middleware"
112
112
113
113
!!! tip "A note about Middy"
114
-
We guarantee support for both Middy.js `v4.x` & `v5.x` with the latter being available only if you are using ES modules.
114
+
We guarantee support for Middy.js `v4.x` through `v6.x` versions.
115
115
Check their docs to learn more about [Middy and its middleware stack](https://middy.js.org/docs/intro/getting-started){target="_blank"} as well as [best practices when working with Powertools](https://middy.js.org/docs/integrations/lambda-powertools#best-practices){target="_blank"}.
|**Service**| Optionally, sets **service** metric dimension across all metrics |`POWERTOOLS_SERVICE_NAME`|`service_undefined`| Any string |`serverlessAirline`|`serviceName`|
72
72
|**Metric namespace**| Logical container where all metrics will be placed |`POWERTOOLS_METRICS_NAMESPACE`|`default_namespace`| Any string |`serverlessAirline`|`default_namespace`|
73
+
|**Enabled**| Whether to emit metrics to standard output or not |`POWERTOOLS_METRICS_ENABLED`|`true`| Boolean |`false`||
73
74
74
75
!!! tip
75
76
Use your application name or main service as the metric namespace to easily group all metrics
@@ -199,7 +200,7 @@ You can add default dimensions to your metrics by passing them as parameters in
199
200
=== "Middy middleware"
200
201
201
202
!!! tip "A note about Middy"
202
-
We guarantee support for both Middy.js `v4.x` & `v5.x` with the latter being available only if you are using ES modules.
203
+
We guarantee support for Middy.js `v4.x` through `v6.x` versions.
203
204
Check their docs to learn more about [Middy and its middleware stack](https://middy.js.org/docs/intro/getting-started){target="_blank"} as well as [best practices when working with Powertools](https://middy.js.org/docs/integrations/lambda-powertools#best-practices){target="_blank"}.
204
205
205
206
```typescript hl_lines="24-26"
@@ -465,22 +466,26 @@ Keep the following formula in mind: `unique metric = (metric_name + dimension_na
465
466
1. Metadata should be added before calling `addMetric()` to ensure it's included in the same EMF blob.
466
467
2. Single metrics are emitted as soon as `addMetric()` is called, so you don't need to call `publishStoredMetrics()`.
467
468
469
+
### Customizing the logger
470
+
471
+
You can customize how Metrics logs warnings and debug messages to standard output by passing a custom logger as a constructor parameter. This is useful when you want to silence warnings or debug messages, or when you want to log them to a different output.
When unit testing your code that uses the `Metrics` utility, you may want to silence the logs emitted by the utility or assert that metrics are being emitted correctly. By default, the utility manages its own `console` instance, which means that you can't easily access or mock the logs emitted by the utility.
481
+
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.
471
482
472
-
To make it easier to test your code, you can set the `POWERTOOLS_DEV` environment variable to `true`to instruct the utility to use the global `console` object instead of its own.
483
+
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`.
473
484
474
-
This allows you to spy on the logs emitted by the utility and assert that the metrics are being emitted correctly.
485
+
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.
When running your tests with both [Jest](https://jestjs.io) and [Vitest](http://vitest.dev), you can use the `--silent` flag to silence the logs emitted by the utility.
Copy file name to clipboardExpand all lines: docs/core/tracer.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -154,7 +154,7 @@ You can quickly start by importing the `Tracer` class, initialize it outside the
154
154
=== "Middy Middleware"
155
155
156
156
!!! tip "A note about Middy"
157
-
We guarantee support for both Middy.js `v4.x` & `v5.x` with the latter being available only if you are using ES modules.
157
+
We guarantee support for Middy.js `v4.x` through `v6.x` versions.
158
158
Check their docs to learn more about [Middy and its middleware stack](https://middy.js.org/docs/intro/getting-started){target="_blank"} as well as [best practices when working with Powertools](https://middy.js.org/docs/integrations/lambda-powertools#best-practices){target="_blank"}.
|**POWERTOOLS_TRACER_CAPTURE_RESPONSE**| Capture Lambda or method return as metadata. |[Tracer](core/tracer.md)|`true`|
339
331
|**POWERTOOLS_TRACER_CAPTURE_ERROR**| Capture Lambda or method exception as metadata. |[Tracer](core/tracer.md)|`true`|
@@ -348,6 +340,18 @@ Core utilities such as Tracing, Logging, and Metrics will be available across al
348
340
349
341
Each Utility page provides information on example values and allowed values.
350
342
343
+
### Optimizing for non-production environments
344
+
345
+
Whether you're prototyping locally or against a non-production environment, you can use `POWERTOOLS_DEV` to increase verbosity across multiple utilities.
346
+
347
+
When `POWERTOOLS_DEV` is set to a truthy value (`1`, `true`), it'll have the following effects:
|__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 |
352
+
|__Tracer__| Disables tracing operations in non-Lambda environments. This already happens automatically in the Tracer utility |
353
+
|__Metrics__| Disables emitting metrics to stdout. Can be overridden by setting `POWERTOOLS_METRICS_ENABLED` to `true`|
354
+
351
355
## Support Powertools for AWS Lambda (TypeScript)
352
356
353
357
There are many ways you can help us gain future investments to improve everyone's experience:
Copy file name to clipboardExpand all lines: docs/upgrade.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -198,7 +198,7 @@ Below is an example of how to configure your `.eslintrc.json` file:
198
198
199
199
### Log sampling
200
200
201
-
!!! note "Disregard if you are not using the [log sampling feature](./core/logger.md#sampling-logs)."
201
+
!!! note "Disregard if you are not using the [log sampling feature](./core/logger.md#sampling-debug-logs)."
202
202
203
203
In v1, log sampling implementation was inconsistent from other Powertools for AWS Lambda languages _(Python, .NET, and Java)_.
204
204
@@ -217,7 +217,7 @@ Logger `sampleRateValue` **continues** to determine the percentage of concurrent
217
217
218
218
In v1, `Logger` exposed the [standard](./core/logger.md#standard-structured-keys) as a single argument, _e.g., `formatAttributes(attributes: UnformattedAttributes)`_. It expected a plain object with keys and values you wanted in the final log output.
219
219
220
-
In v2, you have more control over **standard** (`attributes`) and [**custom keys**](./core/logger.md#appending-persistent-additional-log-keys-and-values) (`additionalLogAttributes`) in the `formatAttributes` method. Also, you now return a `LogItem` object to increase type safety when defining the final log output.
220
+
In v2, you have more control over **standard** (`attributes`) and [**custom keys**](./core/logger.md#appending-additional-keys) (`additionalLogAttributes`) in the `formatAttributes` method. Also, you now return a `LogItem` object to increase type safety when defining the final log output.
Copy file name to clipboardExpand all lines: docs/utilities/idempotency.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -187,7 +187,7 @@ The configuration options for the `@idempotent` decorator are the same as the on
187
187
### MakeHandlerIdempotent Middy middleware
188
188
189
189
!!! tip "A note about Middy"
190
-
We guarantee support for both Middy.js `v4.x`& `v5.x`with the latter being available only if you are using ES modules.
190
+
We guarantee support for Middy.js `v4.x`through `v6.x`versions.
191
191
Check their docs to learn more about [Middy and its middleware stack](https://middy.js.org/docs/intro/getting-started){target="_blank"} as well as [best practices when working with Powertools](https://middy.js.org/docs/integrations/lambda-powertools#best-practices){target="_blank"}.
192
192
193
193
If you are using [Middy.js](https://middy.js.org){target="_blank"} as your middleware engine, you can use the `makeHandlerIdempotent` middleware to make your Lambda handler idempotent.
0 commit comments