@lamware/powertools-metrics
v2.0.1
Published
Lamware Middleware to utilize the official Metrics powertools
Downloads
40
Readme
This Lamware Middleware utilizes the official Lambda TypeScript Powertools provided by AWS to:
- Set-up and memoize a root
Metrics
instance - Publish Metrics automatically after the Function handler executes
- Optionally set-up default dimensions
- Automatically capture various metrics:
- Cold starts
- Function name
Installation
This package is available via NPM:
yarn add @lamware/powertools-metrics
# or
npm install @lamware/powertools-metrics
Usage
import { powertoolsMetrics } from '@lamware/powertools-metrics';
import { MetricUnits } from '@aws-lambda-powertools/metrics';
import type { APIGatewayProxyHandlerV2 } from 'aws-lambda';
import { lamware } from '@lamware/core';
const { handler } = lamware<APIGatewayProxyHandlerV2<any>>()
.use(powertoolsMetrics({
// Options are pass-through to the Tracing instance.
namespace: 'evilkiwi',
serviceName: 'my-api',
}))
.execute(async ({ state }) => {
state.metrics.addMetric('successfulBooking', MetricUnits.Count, 1);
return { statusCode: 200 };
});
export { handler };