Skip to content

Commit 8269677

Browse files
committed
Merge branch 'feat/metrics-middleware' of github.com:awslabs/aws-lambda-powertools-typescript into feat/metrics-middleware
2 parents 9b295ed + d75c40f commit 8269677

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

docs/core/metrics.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ See examples below:
145145
import { Context } from 'aws-lambda';
146146
import middy from '@middy/core';
147147

148-
const metrics = new Metrics({namespace:"serverlessAirline", service:"orders"});
148+
const metrics = new Metrics({ namespace: 'serverlessAirline', service: 'orders' });
149149

150150
const lambdaHandler = async (event: any, context: Context) => {
151151
metrics.addMetric('successfulBooking', MetricUnits.Count, 1);
@@ -205,7 +205,7 @@ If you do not the middleware or decorator, you have to flush your metrics manual
205205
If metrics are provided, and any of the following criteria are not met, a **`RangeError`** exception will be raised:
206206

207207
* Maximum of 9 dimensions
208-
* Namespace is set, and no more than one
208+
* Namespace is set only once (or none)
209209
* Metric units must be [supported by CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html)
210210

211211

@@ -219,7 +219,7 @@ See below an example of how to automatically flush metrics with the Middy-compat
219219
import { Context } from 'aws-lambda';
220220
import middy from '@middy/core';
221221

222-
const metrics = new Metrics({namespace:"exampleApplication", service:"exampleService"});
222+
const metrics = new Metrics({ namespace: 'exampleApplication' , service: 'exampleService' });
223223

224224
const lambdaHandler = async (event: any, context: Context) => {
225225
metrics.addMetric('bookingConfirmation', MetricUnits.Count, 1);
@@ -360,7 +360,7 @@ You can optionally capture cold start metrics with the `logMetrics` middleware o
360360
import { Context } from 'aws-lambda';
361361
import middy from '@middy/core';
362362

363-
const metrics = new Metrics({namespace:"serverlessAirline", service:"orders"});
363+
const metrics = new Metrics({namespace: 'serverlessAirline', service: 'orders' });
364364

365365
const lambdaHandler = async (event: any, context: Context) => {
366366
metrics.addMetric('successfulBooking', MetricUnits.Count, 1);
@@ -377,7 +377,7 @@ You can optionally capture cold start metrics with the `logMetrics` middleware o
377377
import { Context, Callback } from 'aws-lambda';
378378
import middy from '@middy/core';
379379

380-
const metrics = new Metrics({namespace:"serverlessAirline", service:"orders"});
380+
const metrics = new Metrics({namespace: 'serverlessAirline', service: 'orders' });
381381

382382
export class MyFunction {
383383

packages/metrics/examples/decorator/default-dimensions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Lambda implements LambdaInterface {
2121
metrics.addDimension('environment', 'dev');
2222
metrics.addDimension('application', 'hello-world-dev');
2323
metrics.addMetric('test-metric', MetricUnits.Count, 10);
24+
// You can override the default dimensions by clearing the existing metrics first. Note that the cleared metric will be dropped, it will NOT be published to CloudWatch
2425
const metricsObject = metrics.serializeMetrics();
2526
metrics.clearMetrics();
2627
metrics.clearDimensions();

packages/metrics/examples/decorator/empty-metrics.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const metrics = new Metrics();
1515

1616
class Lambda implements LambdaInterface {
1717

18-
@metrics.logMetrics({ raiseOnEmptyMetrics: true })
18+
// Be default, we will not throw any error if there is no metrics. Use this property to override and throw an exception
19+
@metrics.logMetrics({ raiseOnEmptyMetrics: true })
1920
public handler<TEvent, TResult>(_event: TEvent, _context: Context, _callback: Callback<TResult>): void | Promise<TResult> {
2021
// Notice that no metrics are added
2122
// Since the raiseOnEmptyMetrics parameter is set to true, the Powertool throw an Error

packages/metrics/examples/decorator/manual-flushing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const lambdaHandler: Handler = async () => {
1616

1717
metrics.addMetric('test-metric', MetricUnits.Count, 10);
1818
metrics.purgeStoredMetrics();
19-
//Metrics will be logged and cleared
19+
//Metrics will be published and cleared
2020

2121
return {
2222
foo: 'bar'

0 commit comments

Comments
 (0)