cat-a-logs 1.1.4 → 1.1.6
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,10 +36,12 @@ 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;
|
39
41
|
var logger_1 = require("@aws-lambda-powertools/logger");
|
40
42
|
var ajv_1 = require("ajv");
|
41
43
|
//cache entries are structured thusly: 'Namespace + Dimensions(Alphabetically)': EMFObject
|
42
|
-
|
44
|
+
exports.cache = {};
|
43
45
|
//catalog(kilos, "kilos" , "lambda-function-metrics", "Kilograms", {'functionVersion': $LATEST, 'testDimension': derp});
|
44
46
|
function catalog(trackedVariable_1, metricName_1, metricNamespace_1) {
|
45
47
|
return __awaiter(this, arguments, void 0, function (trackedVariable, metricName, metricNamespace, metricUnitLabel, CustomerDefinedDimension, resolution, deploy) {
|
@@ -51,7 +53,7 @@ function catalog(trackedVariable_1, metricName_1, metricNamespace_1) {
|
|
51
53
|
if (deploy === void 0) { deploy = false; }
|
52
54
|
return __generator(this, function (_b) {
|
53
55
|
//Check for any errors & validate inputs based on documentations
|
54
|
-
if (!cache)
|
56
|
+
if (!exports.cache)
|
55
57
|
throw new Error('cache is not found, please import cache from cat-a-log');
|
56
58
|
if (Object.keys(CustomerDefinedDimension).concat([metricName.toLowerCase()]).filter(function (el) { return el === "level" || "message" || "sampling_rate" || "service" || "timestamp" || "xray_trace_id"; }).length > 0)
|
57
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");
|
@@ -170,10 +172,10 @@ function catalog(trackedVariable_1, metricName_1, metricNamespace_1) {
|
|
170
172
|
sortedDimensions[Object.keys(CustomerDefinedDimension).sort()[i]] =
|
171
173
|
CustomerDefinedDimension[Object.keys(CustomerDefinedDimension).sort()[i]];
|
172
174
|
}
|
173
|
-
check = cache["".concat(metricNamespace).concat(sortedDimensions)];
|
175
|
+
check = exports.cache["".concat(metricNamespace).concat(sortedDimensions)];
|
174
176
|
if (check != undefined) {
|
175
177
|
//push the metrics object to Metrics array
|
176
|
-
cache["".concat(metricNamespace).concat(sortedDimensions)]['_aws']['CloudWatchMetrics'][0]['Metrics'].push({
|
178
|
+
exports.cache["".concat(metricNamespace).concat(sortedDimensions)]['_aws']['CloudWatchMetrics'][0]['Metrics'].push({
|
177
179
|
Name: metricName,
|
178
180
|
Unit: metricUnitLabel,
|
179
181
|
StorageResolution: resolution,
|
@@ -215,28 +217,23 @@ function catalog(trackedVariable_1, metricName_1, metricNamespace_1) {
|
|
215
217
|
throw new Error("Supplied/Proposed structured log does not comply with EMF schema");
|
216
218
|
}
|
217
219
|
// If it passes then add to cache object
|
218
|
-
cache["".concat(metricNamespace).concat(sortedDimensions)] = newEmfLog;
|
220
|
+
exports.cache["".concat(metricNamespace).concat(sortedDimensions)] = newEmfLog;
|
219
221
|
}
|
220
222
|
if (deploy) {
|
221
223
|
//after last catalog function is invoked, send all cached logs with logger at once
|
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]]);
|
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]]);
|
224
226
|
}
|
225
227
|
//clear cache
|
226
|
-
console.log("BEFORE:", cache);
|
227
|
-
for (member in cache)
|
228
|
-
delete cache[member];
|
229
|
-
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);
|
230
232
|
}
|
231
233
|
return [2 /*return*/];
|
232
234
|
});
|
233
235
|
});
|
234
236
|
}
|
235
|
-
export {cache, catalog};
|
236
|
-
// exports.default = {
|
237
|
-
// "cache": cache,
|
238
|
-
// "catalog": catalog,
|
239
|
-
// };
|
240
237
|
/*Current Working logger invocation
|
241
238
|
logger.info("Your EMF compliant Structured Metrics Log",
|
242
239
|
Object.assign({
|
package/client/index.ts
CHANGED
@@ -5,9 +5,9 @@ import Ajv from 'ajv';
|
|
5
5
|
|
6
6
|
|
7
7
|
//cache entries are structured thusly: 'Namespace + Dimensions(Alphabetically)': EMFObject
|
8
|
-
const cache: { [key: string]: any } = {};
|
8
|
+
export const cache: { [key: string]: any } = {};
|
9
9
|
//catalog(kilos, "kilos" , "lambda-function-metrics", "Kilograms", {'functionVersion': $LATEST, 'testDimension': derp});
|
10
|
-
async function catalog(
|
10
|
+
export async function catalog(
|
11
11
|
trackedVariable: number | Array<number>,
|
12
12
|
metricName: string,
|
13
13
|
metricNamespace: string,
|
@@ -220,10 +220,6 @@ const validateEmf = ajv.compile(emfSchema);
|
|
220
220
|
}
|
221
221
|
}
|
222
222
|
|
223
|
-
export default {
|
224
|
-
cache,
|
225
|
-
catalog,
|
226
|
-
};
|
227
223
|
|
228
224
|
/*Current Working logger invocation
|
229
225
|
logger.info("Your EMF compliant Structured Metrics Log",
|
@@ -24,9 +24,9 @@ export const lambdaHandler = async (event, context) => {
|
|
24
24
|
message: 'hello world',
|
25
25
|
}),
|
26
26
|
};
|
27
|
-
let kilos =
|
28
|
-
let pounds =
|
29
|
-
let grams =
|
27
|
+
let kilos =70;
|
28
|
+
let pounds =35;
|
29
|
+
let grams = 20;
|
30
30
|
catalog(pounds, 'poundsTest', 'lambda-junction-metrics2', 'None', {
|
31
31
|
functionVersion: '$LATEST',
|
32
32
|
testDimension: 'berp',
|