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
The middleware and the decorator also **validate**, **serialize**, and **flush** all your metrics. During metrics validation, if no metrics are provided then a warning will be logged, but no exception will be raised.
200
+
Using the Middy middleware or decorator will **automatically validate, serialize, and flush** all your metrics. During metrics validation, if no metrics are provided then a warning will be logged, but no exception will be raised.
201
+
If you do not the middleware or decorator, you have to flush your metrics manually.
202
+
203
203
204
204
!!! warning "Metric validation"
205
205
If metrics are provided, and any of the following criteria are not met, a **`RangeError`** exception will be raised:
@@ -257,10 +257,13 @@ See below an example of how to automatically flush metrics with the Middy-compat
257
257
}
258
258
```
259
259
260
-
#### Using the class decorator
260
+
#### Using a class decorator
261
261
262
-
Decorators can only be attached to a class declaration, method, accessor, property, or parameter. Therefore, if prefer to write your handler as a standard function, check the middleware or manual methods instead.
263
-
See the [official TypeScript documentation](https://www.typescriptlang.org/docs/handbook/decorators.html) for more details.
262
+
!!! info
263
+
Decorators can only be attached to a class declaration, method, accessor, property, or parameter. Therefore, if you prefer to write your handler as a standard function rather than a Class method, check the [middleware](#using-a-middleware) or [manual](#manually) method sections instead.
264
+
See the [official TypeScript documentation](https://www.typescriptlang.org/docs/handbook/decorators.html) for more details.
265
+
266
+
The `logMetrics` decorator of the metrics utility can be used when your Lambda handler function is implemented as method of a Class.
264
267
265
268
266
269
```typescript hl_lines="8"
@@ -309,7 +312,7 @@ export class MyFunction {
309
312
310
313
#### Manually
311
314
312
-
If you wish to do so, you can manually flush the metrics with `purgeStoredMetrics` and clear metrics as follows:
315
+
If you wish to do so, you can manually flush metrics with `purgeStoredMetrics` and clear metrics as follows:
313
316
314
317
!!! warning
315
318
Metrics, dimensions and namespace validation still applies.
@@ -392,7 +395,7 @@ If it's a cold start invocation, this feature will:
392
395
393
396
This has the advantage of keeping cold start metric separate from your application metrics, where you might have unrelated dimensions.
394
397
395
-
!!! info "We do not emit 0 as a value for the ColdStart metric for cost-efficiency reasons. [Let us know](https://github.com/awslabs/aws-lambda-powertools-typecsript/issues/new?assignees=&labels=feature-request%2C+triage&template=feature_request.md&title=) if you'd prefer a flag to override it."
398
+
!!! info "We do not emit 0 as a value for the ColdStart metric for cost-efficiency reasons. [Let us know](https://github.com/awslabs/aws-lambda-powertools-typescript/issues/new?assignees=&labels=feature-request%2C+triage&template=feature_request.md&title=) if you'd prefer a flag to override it."
396
399
397
400
## Advanced
398
401
@@ -459,10 +462,9 @@ CloudWatch EMF uses the same dimensions across all your metrics. Use `singleMetr
459
462
460
463
=== "logMetrics middleware"
461
464
462
-
```typescript hl_lines="8 10 12"
465
+
```typescript hl_lines="7 9 11 15"
463
466
import { Metrics, MetricUnits, logMetrics } from '@aws-lambda-powertools/metrics';
464
467
import { Context } from 'aws-lambda';
465
-
import middy from '@middy/core';
466
468
467
469
const metrics = new Metrics({namespace:"serverlessAirline", service:"orders"});
468
470
@@ -480,7 +482,7 @@ CloudWatch EMF uses the same dimensions across all your metrics. Use `singleMetr
480
482
481
483
=== "logMetrics decorator"
482
484
483
-
```typescript hl_lines="11 13 15"
485
+
```typescript hl_lines="9 11 13 15"
484
486
import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';
0 commit comments