forked from aws-powertools/powertools-lambda-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathempty-metrics.ts
23 lines (18 loc) · 903 Bytes
/
empty-metrics.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import * as dummyEvent from '../../../tests/resources/events/custom/hello-world.json';
import { context as dummyContext } from '../../../tests/resources/contexts/hello-world';
import { populateEnvironmentVariables } from '../tests/helpers';
import { Metrics } from '../src';
import middy from '@middy/core';
import { logMetrics } from '../src';
// Populate runtime
populateEnvironmentVariables();
// Additional runtime variables
process.env.POWERTOOLS_METRICS_NAMESPACE = 'hello-world';
const metrics = new Metrics();
const lambdaHandler = async (): Promise<void> => {
// Notice that no metrics are added
// Since the throwOnEmptyMetrics parameter is set to true, the Powertool throws an Error
};
const handlerWithMiddleware = middy(lambdaHandler)
.use(logMetrics(metrics, { throwOnEmptyMetrics: true }));
handlerWithMiddleware(dummyEvent, dummyContext, () => console.log('Lambda invoked!'));