@middy/cloudwatch-metrics 2.5.6 → 2.5.7
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.
- package/index.js +24 -18
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -1,32 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const awsEmbeddedMetrics = require('aws-embedded-metrics');
|
|
2
4
|
|
|
3
5
|
const cloudwatchMetricsMiddleware = (opts = {}) => {
|
|
4
|
-
const defaults = {}
|
|
5
|
-
const options = { ...defaults,
|
|
6
|
+
const defaults = {};
|
|
7
|
+
const options = { ...defaults,
|
|
8
|
+
...opts
|
|
9
|
+
};
|
|
6
10
|
|
|
7
|
-
const cloudwatchMetricsBefore =
|
|
8
|
-
const metrics = awsEmbeddedMetrics.createMetricsLogger()
|
|
11
|
+
const cloudwatchMetricsBefore = request => {
|
|
12
|
+
const metrics = awsEmbeddedMetrics.createMetricsLogger(); // If not set, defaults to aws-embedded-metrics
|
|
9
13
|
|
|
10
|
-
// If not set, defaults to aws-embedded-metrics
|
|
11
14
|
if (options.namespace) {
|
|
12
|
-
metrics.setNamespace(options.namespace)
|
|
13
|
-
}
|
|
15
|
+
metrics.setNamespace(options.namespace);
|
|
16
|
+
} // If not set, defaults to ServiceName, ServiceType and LogGroupName
|
|
17
|
+
|
|
14
18
|
|
|
15
|
-
// If not set, defaults to ServiceName, ServiceType and LogGroupName
|
|
16
19
|
if (options.dimensions) {
|
|
17
|
-
metrics.setDimensions(...options.dimensions)
|
|
20
|
+
metrics.setDimensions(...options.dimensions);
|
|
18
21
|
}
|
|
19
|
-
Object.assign(request.context, { metrics })
|
|
20
|
-
}
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
Object.assign(request.context, {
|
|
24
|
+
metrics
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const cloudwatchMetricsAfter = async request => {
|
|
29
|
+
await request.context.metrics.flush();
|
|
30
|
+
};
|
|
25
31
|
|
|
26
32
|
return {
|
|
27
33
|
before: cloudwatchMetricsBefore,
|
|
28
34
|
after: cloudwatchMetricsAfter
|
|
29
|
-
}
|
|
30
|
-
}
|
|
35
|
+
};
|
|
36
|
+
};
|
|
31
37
|
|
|
32
|
-
module.exports = cloudwatchMetricsMiddleware
|
|
38
|
+
module.exports = cloudwatchMetricsMiddleware;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/cloudwatch-metrics",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.7",
|
|
4
4
|
"description": "Embedded CloudWatch metrics middleware for the middy framework",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"engines": {
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"aws-embedded-metrics": "2.0.4"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@middy/core": "^2.5.
|
|
55
|
+
"@middy/core": "^2.5.7"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "3983c4b138e1a4d7fcb3ed805d3b8832fff06fc1"
|
|
58
58
|
}
|