@middy/cloudwatch-metrics 5.0.0-alpha.1 → 5.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +36 -37
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -1,38 +1,37 @@
1
- import awsEmbeddedMetrics from 'aws-embedded-metrics'
1
+ import awsEmbeddedMetrics from 'aws-embedded-metrics';
2
+ const defaults = {};
3
+ const cloudwatchMetricsMiddleware = (opts = {})=>{
4
+ const { namespace, dimensions } = {
5
+ ...defaults,
6
+ ...opts
7
+ };
8
+ const cloudwatchMetricsBefore = (request)=>{
9
+ const metrics = awsEmbeddedMetrics.createMetricsLogger();
10
+ // If not set, defaults to aws-embedded-metrics
11
+ if (namespace) {
12
+ metrics.setNamespace(namespace);
13
+ }
14
+ // If not set, keeps defaults as defined here https://github.com/awslabs/aws-embedded-metrics-node/#configuration
15
+ if (dimensions) {
16
+ metrics.setDimensions(dimensions);
17
+ }
18
+ Object.assign(request.context, {
19
+ metrics
20
+ });
21
+ };
22
+ const cloudwatchMetricsAfter = async (request)=>{
23
+ await request.context.metrics.flush();
24
+ };
25
+ const cloudwatchMetricsOnError = async (request)=>{
26
+ try {
27
+ await cloudwatchMetricsAfter(request);
28
+ } catch (e) {}
29
+ };
30
+ return {
31
+ before: cloudwatchMetricsBefore,
32
+ after: cloudwatchMetricsAfter,
33
+ onError: cloudwatchMetricsOnError
34
+ };
35
+ };
36
+ export default cloudwatchMetricsMiddleware;
2
37
 
3
- const defaults = {}
4
-
5
- const cloudwatchMetricsMiddleware = (opts = {}) => {
6
- const { namespace, dimensions } = { ...defaults, ...opts }
7
- const cloudwatchMetricsBefore = (request) => {
8
- const metrics = awsEmbeddedMetrics.createMetricsLogger()
9
-
10
- // If not set, defaults to aws-embedded-metrics
11
- if (namespace) {
12
- metrics.setNamespace(namespace)
13
- }
14
-
15
- // If not set, keeps defaults as defined here https://github.com/awslabs/aws-embedded-metrics-node/#configuration
16
- if (dimensions) {
17
- metrics.setDimensions(dimensions)
18
- }
19
- Object.assign(request.context, { metrics })
20
- }
21
-
22
- const cloudwatchMetricsAfter = async (request) => {
23
- await request.context.metrics.flush()
24
- }
25
- const cloudwatchMetricsOnError = async (request) => {
26
- try {
27
- await cloudwatchMetricsAfter(request)
28
- } catch (e) {}
29
- }
30
-
31
- return {
32
- before: cloudwatchMetricsBefore,
33
- after: cloudwatchMetricsAfter,
34
- onError: cloudwatchMetricsOnError
35
- }
36
- }
37
-
38
- export default cloudwatchMetricsMiddleware
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/cloudwatch-metrics",
3
- "version": "5.0.0-alpha.1",
3
+ "version": "5.0.0-alpha.2",
4
4
  "description": "Embedded CloudWatch metrics middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -66,7 +66,7 @@
66
66
  "aws-embedded-metrics": "4.1.0"
67
67
  },
68
68
  "devDependencies": {
69
- "@middy/core": "5.0.0-alpha.1",
69
+ "@middy/core": "5.0.0-alpha.2",
70
70
  "@types/aws-lambda": "^8.10.101"
71
71
  },
72
72
  "gitHead": "ebce8d5df8783077fa49ba62ee9be20e8486a7f1"