cat-a-logs 1.1.5 → 1.1.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.
Potentially problematic release.
This version of cat-a-logs might be problematic. Click here for more details.
package/client/index.js
CHANGED
@@ -41,8 +41,7 @@ exports.catalog = catalog;
|
|
41
41
|
var logger_1 = require("@aws-lambda-powertools/logger");
|
42
42
|
var ajv_1 = require("ajv");
|
43
43
|
//cache entries are structured thusly: 'Namespace + Dimensions(Alphabetically)': EMFObject
|
44
|
-
|
45
|
-
exports.cache = cache;
|
44
|
+
exports.cache = {};
|
46
45
|
//catalog(kilos, "kilos" , "lambda-function-metrics", "Kilograms", {'functionVersion': $LATEST, 'testDimension': derp});
|
47
46
|
function catalog(trackedVariable_1, metricName_1, metricNamespace_1) {
|
48
47
|
return __awaiter(this, arguments, void 0, function (trackedVariable, metricName, metricNamespace, metricUnitLabel, CustomerDefinedDimension, resolution, deploy) {
|
@@ -54,7 +53,7 @@ function catalog(trackedVariable_1, metricName_1, metricNamespace_1) {
|
|
54
53
|
if (deploy === void 0) { deploy = false; }
|
55
54
|
return __generator(this, function (_b) {
|
56
55
|
//Check for any errors & validate inputs based on documentations
|
57
|
-
if (!cache)
|
56
|
+
if (!exports.cache)
|
58
57
|
throw new Error('cache is not found, please import cache from cat-a-log');
|
59
58
|
if (Object.keys(CustomerDefinedDimension).concat([metricName.toLowerCase()]).filter(function (el) { return el === "level" || "message" || "sampling_rate" || "service" || "timestamp" || "xray_trace_id"; }).length > 0)
|
60
59
|
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");
|
@@ -66,7 +65,7 @@ function catalog(trackedVariable_1, metricName_1, metricNamespace_1) {
|
|
66
65
|
throw new Error('EMF has a limit of 30 user defined dimension keys per log');
|
67
66
|
}
|
68
67
|
logger = new logger_1.Logger({ serviceName: 'serverlessAirline' });
|
69
|
-
ajv = new ajv_1.
|
68
|
+
ajv = new ajv_1.Ajv();
|
70
69
|
emfSchema = {
|
71
70
|
type: 'object',
|
72
71
|
title: 'Root Node',
|
@@ -173,10 +172,10 @@ function catalog(trackedVariable_1, metricName_1, metricNamespace_1) {
|
|
173
172
|
sortedDimensions[Object.keys(CustomerDefinedDimension).sort()[i]] =
|
174
173
|
CustomerDefinedDimension[Object.keys(CustomerDefinedDimension).sort()[i]];
|
175
174
|
}
|
176
|
-
check = cache["".concat(metricNamespace).concat(sortedDimensions)];
|
175
|
+
check = exports.cache["".concat(metricNamespace).concat(sortedDimensions)];
|
177
176
|
if (check != undefined) {
|
178
177
|
//push the metrics object to Metrics array
|
179
|
-
cache["".concat(metricNamespace).concat(sortedDimensions)]['_aws']['CloudWatchMetrics'][0]['Metrics'].push({
|
178
|
+
exports.cache["".concat(metricNamespace).concat(sortedDimensions)]['_aws']['CloudWatchMetrics'][0]['Metrics'].push({
|
180
179
|
Name: metricName,
|
181
180
|
Unit: metricUnitLabel,
|
182
181
|
StorageResolution: resolution,
|
@@ -218,23 +217,24 @@ function catalog(trackedVariable_1, metricName_1, metricNamespace_1) {
|
|
218
217
|
throw new Error("Supplied/Proposed structured log does not comply with EMF schema");
|
219
218
|
}
|
220
219
|
// If it passes then add to cache object
|
221
|
-
cache["".concat(metricNamespace).concat(sortedDimensions)] = newEmfLog;
|
220
|
+
exports.cache["".concat(metricNamespace).concat(sortedDimensions)] = newEmfLog;
|
222
221
|
}
|
223
222
|
if (deploy) {
|
224
223
|
//after last catalog function is invoked, send all cached logs with logger at once
|
225
|
-
for (i = 0; i < Object.keys(cache).length; i++) {
|
226
|
-
logger.info("Your EMF compliant Structured Metrics Log ".concat(i + 1), cache[Object.keys(cache)[i]]);
|
224
|
+
for (i = 0; i < Object.keys(exports.cache).length; i++) {
|
225
|
+
logger.info("Your EMF compliant Structured Metrics Log ".concat(i + 1), exports.cache[Object.keys(exports.cache)[i]]);
|
227
226
|
}
|
228
227
|
//clear cache
|
229
|
-
console.log("BEFORE:", cache);
|
230
|
-
for (member in cache)
|
231
|
-
delete cache[member];
|
232
|
-
console.log("AFTER:", cache);
|
228
|
+
console.log("BEFORE:", exports.cache);
|
229
|
+
for (member in exports.cache)
|
230
|
+
delete exports.cache[member];
|
231
|
+
console.log("AFTER:", exports.cache);
|
233
232
|
}
|
234
233
|
return [2 /*return*/];
|
235
234
|
});
|
236
235
|
});
|
237
236
|
}
|
237
|
+
// export { cache, catalog };
|
238
238
|
/*Current Working logger invocation
|
239
239
|
logger.info("Your EMF compliant Structured Metrics Log",
|
240
240
|
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
|
-
const cache: { [key: string]: any } = {};
|
7
|
+
export const cache: { [key: string]: any } = {};
|
9
8
|
//catalog(kilos, "kilos" , "lambda-function-metrics", "Kilograms", {'functionVersion': $LATEST, 'testDimension': derp});
|
10
|
-
async function catalog(
|
9
|
+
export async function catalog(
|
11
10
|
trackedVariable: number | Array<number>,
|
12
11
|
metricName: string,
|
13
12
|
metricNamespace: string,
|
@@ -219,11 +218,7 @@ const validateEmf = ajv.compile(emfSchema);
|
|
219
218
|
console.log("AFTER:", cache);
|
220
219
|
}
|
221
220
|
}
|
222
|
-
|
223
|
-
export {
|
224
|
-
cache,
|
225
|
-
catalog,
|
226
|
-
};
|
221
|
+
// export { cache, catalog };
|
227
222
|
|
228
223
|
/*Current Working logger invocation
|
229
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. */
|