@middy/cloudwatch-metrics 6.1.5 → 6.2.0
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.d.ts +12 -12
- package/index.js +30 -30
- package/package.json +71 -74
package/index.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import middy from
|
|
2
|
-
import { MetricsLogger } from
|
|
3
|
-
import type { Context as LambdaContext } from
|
|
4
|
-
export { MetricsLogger } from
|
|
1
|
+
import type middy from "@middy/core";
|
|
2
|
+
import type { MetricsLogger } from "aws-embedded-metrics";
|
|
3
|
+
import type { Context as LambdaContext } from "aws-lambda";
|
|
4
|
+
export { MetricsLogger } from "aws-embedded-metrics";
|
|
5
5
|
|
|
6
6
|
interface Options {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
namespace?: string;
|
|
8
|
+
dimensions?: Array<Record<string, string>>;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export type Context = LambdaContext & {
|
|
12
|
-
|
|
13
|
-
}
|
|
12
|
+
metrics: MetricsLogger;
|
|
13
|
+
};
|
|
14
14
|
|
|
15
|
-
declare function cloudwatchMetrics
|
|
16
|
-
|
|
17
|
-
): middy.MiddlewareObj<unknown, any, Error, Context
|
|
15
|
+
declare function cloudwatchMetrics(
|
|
16
|
+
options?: Options,
|
|
17
|
+
): middy.MiddlewareObj<unknown, any, Error, Context>;
|
|
18
18
|
|
|
19
|
-
export default cloudwatchMetrics
|
|
19
|
+
export default cloudwatchMetrics;
|
package/index.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import awsEmbeddedMetrics from
|
|
1
|
+
import awsEmbeddedMetrics from "aws-embedded-metrics";
|
|
2
2
|
|
|
3
|
-
const defaults = {}
|
|
3
|
+
const defaults = {};
|
|
4
4
|
|
|
5
5
|
const cloudwatchMetricsMiddleware = (opts = {}) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const { namespace, dimensions } = { ...defaults, ...opts };
|
|
7
|
+
const cloudwatchMetricsBefore = (request) => {
|
|
8
|
+
const metrics = awsEmbeddedMetrics.createMetricsLogger();
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
// If not set, defaults to aws-embedded-metrics
|
|
11
|
+
if (namespace) {
|
|
12
|
+
metrics.setNamespace(namespace);
|
|
13
|
+
}
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
31
|
+
return {
|
|
32
|
+
before: cloudwatchMetricsBefore,
|
|
33
|
+
after: cloudwatchMetricsAfter,
|
|
34
|
+
onError: cloudwatchMetricsOnError,
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
37
|
|
|
38
|
-
export default cloudwatchMetricsMiddleware
|
|
38
|
+
export default cloudwatchMetricsMiddleware;
|
package/package.json
CHANGED
|
@@ -1,76 +1,73 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"@types/aws-lambda": "^8.10.101"
|
|
74
|
-
},
|
|
75
|
-
"gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"
|
|
2
|
+
"name": "@middy/cloudwatch-metrics",
|
|
3
|
+
"version": "6.2.0",
|
|
4
|
+
"description": "Embedded CloudWatch metrics middleware for the middy framework",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=14"
|
|
8
|
+
},
|
|
9
|
+
"engineStrict": true,
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"module": "./index.js",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": {
|
|
17
|
+
"types": "./index.d.ts",
|
|
18
|
+
"default": "./index.js"
|
|
19
|
+
},
|
|
20
|
+
"require": {
|
|
21
|
+
"default": "./index.js"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"types": "index.d.ts",
|
|
26
|
+
"files": ["index.js", "index.d.ts"],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"test": "npm run test:unit && npm run test:fuzz",
|
|
29
|
+
"test:unit": "node --test",
|
|
30
|
+
"test:fuzz": "node --test index.fuzz.js",
|
|
31
|
+
"test:perf": "node --test index.perf.js"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"keywords": [
|
|
35
|
+
"Lambda",
|
|
36
|
+
"Middleware",
|
|
37
|
+
"Serverless",
|
|
38
|
+
"Framework",
|
|
39
|
+
"AWS",
|
|
40
|
+
"AWS Lambda",
|
|
41
|
+
"Middy",
|
|
42
|
+
"HTTP",
|
|
43
|
+
"API",
|
|
44
|
+
"Metrics",
|
|
45
|
+
"Custom Metrics",
|
|
46
|
+
"Embedded Metrics",
|
|
47
|
+
"CloudWatch"
|
|
48
|
+
],
|
|
49
|
+
"author": {
|
|
50
|
+
"name": "Middy contributors",
|
|
51
|
+
"url": "https://github.com/middyjs/middy/graphs/contributors"
|
|
52
|
+
},
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "git+https://github.com/middyjs/middy.git",
|
|
56
|
+
"directory": "packages/cloudwatch-metrics"
|
|
57
|
+
},
|
|
58
|
+
"bugs": {
|
|
59
|
+
"url": "https://github.com/middyjs/middy/issues"
|
|
60
|
+
},
|
|
61
|
+
"homepage": "https://middy.js.org",
|
|
62
|
+
"funding": {
|
|
63
|
+
"type": "github",
|
|
64
|
+
"url": "https://github.com/sponsors/willfarrell"
|
|
65
|
+
},
|
|
66
|
+
"dependencies": {
|
|
67
|
+
"aws-embedded-metrics": "4.2.0"
|
|
68
|
+
},
|
|
69
|
+
"devDependencies": {
|
|
70
|
+
"@types/aws-lambda": "^8.10.101"
|
|
71
|
+
},
|
|
72
|
+
"gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"
|
|
76
73
|
}
|