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/metrics.md
+29-2
Original file line number
Diff line number
Diff line change
@@ -3,8 +3,6 @@ title: Metrics
3
3
description: Core utility
4
4
---
5
5
6
-
<!-- markdownlint-disable MD043 -->
7
-
8
6
Metrics creates custom metrics asynchronously by logging metrics to standard output following [Amazon CloudWatch Embedded Metric Format (EMF)](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format.html).
9
7
10
8
These metrics can be visualized through [Amazon CloudWatch Console](https://console.aws.amazon.com/cloudwatch/).
@@ -460,3 +458,32 @@ CloudWatch EMF uses the same dimensions across all your metrics. Use `singleMetr
460
458
```
461
459
462
460
1. Binding your handler method allows your handler to access `this` within the class methods.
461
+
462
+
## Testing your code
463
+
464
+
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.
465
+
466
+
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.
467
+
468
+
This allows you to spy on the logs emitted by the utility and assert that the metrics are being emitted correctly.
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.
@@ -103,7 +103,7 @@ You can use Powertools for AWS Lambda (TypeScript) by installing it with your fa
103
103
}
104
104
```
105
105
106
-
If you use `esbuild` to bundle your code, make sure to exclude `@aws-lambda-powertools` from being bundled since the packages will be already present the Layer:
106
+
If you use `esbuild` to bundle your code, make sure to exclude `@aws-lambda-powertools/*` and `@aws-sdk/*` from being bundled since the packages are already present the layer:
107
107
108
108
```typescript
109
109
new NodejsFunction(this, 'Function', {
@@ -129,7 +129,7 @@ You can use Powertools for AWS Lambda (TypeScript) by installing it with your fa
If you use `esbuild` to bundle your code, make sure to exclude `@aws-lambda-powertools` from being bundled since the packages will be already present the Layer:
132
+
If you use `esbuild` to bundle your code, make sure to exclude `@aws-lambda-powertools/*` and `@aws-sdk/*` from being bundled since the packages are already present the layer:
133
133
134
134
```yaml hl_lines="5-14"
135
135
MyLambdaFunction:
@@ -142,10 +142,8 @@ You can use Powertools for AWS Lambda (TypeScript) by installing it with your fa
142
142
BuildProperties:
143
143
Minify: true
144
144
External:
145
-
- '@aws-lambda-powertools/commons'
146
-
- '@aws-lambda-powertools/logger'
147
-
- '@aws-lambda-powertools/metrics'
148
-
- '@aws-lambda-powertools/tracer'
145
+
- '@aws-lambda-powertools/*'
146
+
- '@aws-sdk/*'
149
147
```
150
148
151
149
Check the [documentation](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-build-typescript.html) for more details.
@@ -160,16 +158,14 @@ You can use Powertools for AWS Lambda (TypeScript) by installing it with your fa
If you use `esbuild` to bundle your code, make sure to exclude `@aws-lambda-powertools` from being bundled since the packages will be already present the Layer:
161
+
If you use `esbuild` to bundle your code, make sure to exclude `@aws-lambda-powertools/*` and `@aws-sdk/*` from being bundled since the packages are already present the layer:
164
162
165
163
```yaml
166
164
custom:
167
165
esbuild:
168
166
external:
169
-
- '@aws-lambda-powertools/commons'
170
-
- '@aws-lambda-powertools/logger'
171
-
- '@aws-lambda-powertools/metrics'
172
-
- '@aws-lambda-powertools/tracer'
167
+
- '@aws-lambda-powertools/*'
168
+
- '@aws-sdk/*'
173
169
```
174
170
175
171
Check the [documentation](https://floydspace.github.io/serverless-esbuild/) for more details.
@@ -193,7 +189,7 @@ You can use Powertools for AWS Lambda (TypeScript) by installing it with your fa
Copy file name to clipboardExpand all lines: docs/upgrade.md
+21
Original file line number
Diff line number
Diff line change
@@ -173,6 +173,27 @@ In v2, you can now directly import from the `types` subpath export, e.g., `@aws-
173
173
import { LogAttributes, UnformattedAttributes } from '@aws-lambda-powertools/logger/types';
174
174
```
175
175
176
+
### Using eslint?
177
+
178
+
When using `eslint`, you might need to use [`@typescript-eslint/parser`](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) and [`eslint-plugin-import`](https://www.npmjs.com/package/eslint-import-resolver-typescript) to resolve the new subpath imports.
179
+
180
+
Below is an example of how to configure your `.eslintrc.json` file:
0 commit comments