cat-a-logs 1.1.6 → 1.1.8
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.
Potentially problematic release.
This version of cat-a-logs might be problematic. Click here for more details.
package/client/index.js
CHANGED
@@ -36,12 +36,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
36
36
|
}
|
37
37
|
};
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
39
|
-
exports.cache = void 0;
|
40
|
-
exports.catalog = catalog;
|
41
39
|
var logger_1 = require("@aws-lambda-powertools/logger");
|
42
40
|
var ajv_1 = require("ajv");
|
43
41
|
//cache entries are structured thusly: 'Namespace + Dimensions(Alphabetically)': EMFObject
|
44
|
-
|
42
|
+
var cache = {};
|
45
43
|
//catalog(kilos, "kilos" , "lambda-function-metrics", "Kilograms", {'functionVersion': $LATEST, 'testDimension': derp});
|
46
44
|
function catalog(trackedVariable_1, metricName_1, metricNamespace_1) {
|
47
45
|
return __awaiter(this, arguments, void 0, function (trackedVariable, metricName, metricNamespace, metricUnitLabel, CustomerDefinedDimension, resolution, deploy) {
|
@@ -53,7 +51,7 @@ function catalog(trackedVariable_1, metricName_1, metricNamespace_1) {
|
|
53
51
|
if (deploy === void 0) { deploy = false; }
|
54
52
|
return __generator(this, function (_b) {
|
55
53
|
//Check for any errors & validate inputs based on documentations
|
56
|
-
if (!
|
54
|
+
if (!cache)
|
57
55
|
throw new Error('cache is not found, please import cache from cat-a-log');
|
58
56
|
if (Object.keys(CustomerDefinedDimension).concat([metricName.toLowerCase()]).filter(function (el) { return el === "level" || "message" || "sampling_rate" || "service" || "timestamp" || "xray_trace_id"; }).length > 0)
|
59
57
|
throw new Error("metricName, or Dimension names cannot be the same as these native logger keys: level || message || sampling_rate || service || timestamp || xray_trace_id");
|
@@ -65,7 +63,7 @@ function catalog(trackedVariable_1, metricName_1, metricNamespace_1) {
|
|
65
63
|
throw new Error('EMF has a limit of 30 user defined dimension keys per log');
|
66
64
|
}
|
67
65
|
logger = new logger_1.Logger({ serviceName: 'serverlessAirline' });
|
68
|
-
ajv = new ajv_1.
|
66
|
+
ajv = new ajv_1.Ajv();
|
69
67
|
emfSchema = {
|
70
68
|
type: 'object',
|
71
69
|
title: 'Root Node',
|
@@ -172,10 +170,10 @@ function catalog(trackedVariable_1, metricName_1, metricNamespace_1) {
|
|
172
170
|
sortedDimensions[Object.keys(CustomerDefinedDimension).sort()[i]] =
|
173
171
|
CustomerDefinedDimension[Object.keys(CustomerDefinedDimension).sort()[i]];
|
174
172
|
}
|
175
|
-
check =
|
173
|
+
check = cache["".concat(metricNamespace).concat(sortedDimensions)];
|
176
174
|
if (check != undefined) {
|
177
175
|
//push the metrics object to Metrics array
|
178
|
-
|
176
|
+
cache["".concat(metricNamespace).concat(sortedDimensions)]['_aws']['CloudWatchMetrics'][0]['Metrics'].push({
|
179
177
|
Name: metricName,
|
180
178
|
Unit: metricUnitLabel,
|
181
179
|
StorageResolution: resolution,
|
@@ -217,23 +215,24 @@ function catalog(trackedVariable_1, metricName_1, metricNamespace_1) {
|
|
217
215
|
throw new Error("Supplied/Proposed structured log does not comply with EMF schema");
|
218
216
|
}
|
219
217
|
// If it passes then add to cache object
|
220
|
-
|
218
|
+
cache["".concat(metricNamespace).concat(sortedDimensions)] = newEmfLog;
|
221
219
|
}
|
222
220
|
if (deploy) {
|
223
221
|
//after last catalog function is invoked, send all cached logs with logger at once
|
224
|
-
for (i = 0; i < Object.keys(
|
225
|
-
logger.info("Your EMF compliant Structured Metrics Log ".concat(i + 1),
|
222
|
+
for (i = 0; i < Object.keys(cache).length; i++) {
|
223
|
+
logger.info("Your EMF compliant Structured Metrics Log ".concat(i + 1), cache[Object.keys(cache)[i]]);
|
226
224
|
}
|
227
225
|
//clear cache
|
228
|
-
console.log("BEFORE:",
|
229
|
-
for (member in
|
230
|
-
delete
|
231
|
-
console.log("AFTER:",
|
226
|
+
console.log("BEFORE:", cache);
|
227
|
+
for (member in cache)
|
228
|
+
delete cache[member];
|
229
|
+
console.log("AFTER:", cache);
|
232
230
|
}
|
233
231
|
return [2 /*return*/];
|
234
232
|
});
|
235
233
|
});
|
236
234
|
}
|
235
|
+
exports.default = { catalog: catalog };
|
237
236
|
/*Current Working logger invocation
|
238
237
|
logger.info("Your EMF compliant Structured Metrics Log",
|
239
238
|
Object.assign({
|
package/client/index.ts
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
import { Logger } from '@aws-lambda-powertools/logger';
|
2
|
-
import {
|
3
|
-
import Ajv from 'ajv';
|
2
|
+
import { Ajv } from 'ajv';
|
4
3
|
|
5
4
|
|
6
5
|
|
7
6
|
//cache entries are structured thusly: 'Namespace + Dimensions(Alphabetically)': EMFObject
|
8
|
-
|
7
|
+
const cache: { [key: string]: any } = {};
|
9
8
|
//catalog(kilos, "kilos" , "lambda-function-metrics", "Kilograms", {'functionVersion': $LATEST, 'testDimension': derp});
|
10
|
-
|
9
|
+
async function catalog(
|
11
10
|
trackedVariable: number | Array<number>,
|
12
11
|
metricName: string,
|
13
12
|
metricNamespace: string,
|
@@ -219,7 +218,7 @@ const validateEmf = ajv.compile(emfSchema);
|
|
219
218
|
console.log("AFTER:", cache);
|
220
219
|
}
|
221
220
|
}
|
222
|
-
|
221
|
+
export default {catalog};
|
223
222
|
|
224
223
|
/*Current Working logger invocation
|
225
224
|
logger.info("Your EMF compliant Structured Metrics Log",
|
@@ -14,8 +14,7 @@
|
|
14
14
|
import { Logger } from '@aws-lambda-powertools/logger';
|
15
15
|
const logger = new Logger({ serviceName: 'serverlessAirline' });
|
16
16
|
import Ajv from 'ajv';
|
17
|
-
|
18
|
-
import {cache, catalog} from "cat-a-logs/index.js";
|
17
|
+
import { catalog } from "cat-a-logs/index.js";
|
19
18
|
|
20
19
|
export const lambdaHandler = async (event, context) => {
|
21
20
|
const response = {
|
package/package.json
CHANGED
package/tsconfig.json
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
12
12
|
|
13
13
|
/* Language and Environment */
|
14
|
-
"target": "
|
14
|
+
"target": "ES2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
15
15
|
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
16
16
|
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
17
17
|
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
@@ -25,9 +25,9 @@
|
|
25
25
|
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
26
26
|
|
27
27
|
/* Modules */
|
28
|
-
"module": "
|
28
|
+
"module": "NodeNext", /* Specify what module code is generated. */
|
29
29
|
"rootDir": "./", /* Specify the root folder within your source files. */
|
30
|
-
|
30
|
+
"moduleResolution": "NodeNext", /* Specify how TypeScript looks up a file from a given module specifier. */
|
31
31
|
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
32
32
|
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
33
33
|
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
@@ -51,14 +51,14 @@
|
|
51
51
|
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
52
52
|
|
53
53
|
/* Emit */
|
54
|
-
|
54
|
+
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
55
55
|
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
56
56
|
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
57
57
|
"sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
58
58
|
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. -BMA: enabled for jest support */
|
59
59
|
"noEmit": true, /* Disable emitting files from a compilation. */
|
60
60
|
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
61
|
-
|
61
|
+
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
62
62
|
// "removeComments": true, /* Disable emitting comments. */
|
63
63
|
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
64
64
|
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|