@middy/cloudwatch-metrics 3.0.0-alpha.0 → 3.0.0-alpha.4

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 +35 -0
  2. package/package.json +6 -4
package/index.js ADDED
@@ -0,0 +1,35 @@
1
+ import awsEmbeddedMetrics from 'aws-embedded-metrics';
2
+ const defaults = {};
3
+
4
+ const cloudwatchMetricsMiddleware = (opts = {}) => {
5
+ const options = { ...defaults,
6
+ ...opts
7
+ };
8
+
9
+ const cloudwatchMetricsBefore = request => {
10
+ const metrics = awsEmbeddedMetrics.createMetricsLogger();
11
+
12
+ if (options.namespace) {
13
+ metrics.setNamespace(options.namespace);
14
+ }
15
+
16
+ if (options.dimensions) {
17
+ metrics.setDimensions(...options.dimensions);
18
+ }
19
+
20
+ Object.assign(request.context, {
21
+ metrics
22
+ });
23
+ };
24
+
25
+ const cloudwatchMetricsAfter = async request => {
26
+ await request.context.metrics.flush();
27
+ };
28
+
29
+ return {
30
+ before: cloudwatchMetricsBefore,
31
+ after: cloudwatchMetricsAfter
32
+ };
33
+ };
34
+
35
+ export default cloudwatchMetricsMiddleware;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/cloudwatch-metrics",
3
- "version": "3.0.0-alpha.0",
3
+ "version": "3.0.0-alpha.4",
4
4
  "description": "Embedded CloudWatch metrics middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -13,11 +13,13 @@
13
13
  "exports": "./index.js",
14
14
  "types": "index.d.ts",
15
15
  "files": [
16
+ "index.js",
16
17
  "index.d.ts"
17
18
  ],
18
19
  "scripts": {
19
20
  "test": "npm run test:unit",
20
- "test:unit": "ava"
21
+ "test:unit": "ava",
22
+ "test:benchmark": "node __benchmarks__/index.js"
21
23
  },
22
24
  "license": "MIT",
23
25
  "keywords": [
@@ -52,7 +54,7 @@
52
54
  "aws-embedded-metrics": "2.0.4"
53
55
  },
54
56
  "devDependencies": {
55
- "@middy/core": "^3.0.0-alpha.0"
57
+ "@middy/core": "^3.0.0-alpha.4"
56
58
  },
57
- "gitHead": "c533f62841c8a39d061d7b94f30ba178f002c8db"
59
+ "gitHead": "d4bea7f4e21f6a9bbb1f6f6908361169598b9e53"
58
60
  }