cat-a-logs 2.0.4 → 2.0.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.
package/README.md CHANGED
@@ -32,7 +32,7 @@ EMF is a JSON specification that enables CloudWatch Logs to automatically extrac
32
32
  Your chosen Integrated Development Environment (i.e. VS Code) must already be connected to AWS Lambda. For more guidance on setting up AWS Lambda we recommend following this helpful tutorial from AWS: <a href="https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-getting-started-hello-world.html" target="_blank">Deploy Hello World Application with AWS SAM</a>
33
33
 
34
34
  **Installation:**
35
- 1. Install our package using the command `npm install cat-a-logs` then import the function into your js file that connects to AWS Lambda `import { catalog } from "cat-a-logs/index.js";` Check out Cat-A-Log on npm using the attached link:
35
+ 1. Install our package using the command `npm install cat-a-logs` then import the functions into your js file that connects to AWS Lambda `import { deployCatalog, catalog } from "cat-a-logs/index.js";` Check out Cat-A-Log on npm using the attached link:
36
36
  <a href="https://www.npmjs.com/package/cat-a-logs?activeTab=readme" target="_blank">Cat-A-Log</a>
37
37
 
38
38
  2. Now enter your arguments into the catalog function! Let's go through each parameter one at a time and see what this looks like. First let's take a look at the function definition:
@@ -95,14 +95,7 @@ Your chosen Integrated Development Environment (i.e. VS Code) must already be co
95
95
 
96
96
 
97
97
  4. ON the very last function call - it is important to change the deploy parameter to `true`.
98
- ```
99
- function catalog(
100
- .
101
- .
102
- .
103
- .
104
- deploy: boolean = true)
105
- ```
98
+ - Alternative approach is to deploy your Lambda function with the `deployCatalog()` function call. This will automatically publish to CloudWatch without the need to use the entire arguments required in Cat-A-Log. Place `deployCatalog()` after you last catalog function call.
106
99
 
107
100
  5. Deploy your code with AWS SAM. This will place the file in AWS Lambda waiting for invocation. If you would like to learn more about deploying with SAM please follow the attached
108
101
  <a href= "https://docs.aws.amazon.com/lambda/latest/dg/testing-functions.html" target="_blank">link</a>
package/client/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Logger } from "@aws-lambda-powertools/logger";
2
2
  import { Ajv } from "ajv";
3
3
 
4
- //cache entries are structured thusly: 'Namespace + Dimensions(Alphabetically)': EMFObject
4
+ //cache entries are structured thusly: 'Namespace + DimensionsKeys(Alphabetically)': EMFObject
5
5
  const cache: { [key: string]: any } = {};
6
6
  //let latency = 300; (Example metric to track)
7
7
  //Example for in-line use of Cat-a-log w/maximum arguments: catalog(latency, "Latency" , "lambda-function-metrics", "Milliseconds", {'functionVersion': '$LATEST', 'Server': 'Prod'}, 60, deploy);
@@ -25,7 +25,7 @@ async function catalog(
25
25
  if(badKeys.includes(yourKeys[i])){
26
26
  //if a dimension name or metric name conflicts with native logger keys, throw error
27
27
  throw new Error(
28
- "metricName, or Dimension names cannot be the same as these native logger keys: level || message || sampling_rate || service || timestamp || xray_trace_id"
28
+ "metricName, or Dimension names CANNOT be the same as these native Logger keys: level || message || sampling_rate || service || timestamp || xray_trace_id"
29
29
  );
30
30
  }
31
31
  }
@@ -37,11 +37,11 @@ async function catalog(
37
37
  throw new Error("metric value cannot have more than 100 elements");
38
38
  }
39
39
  //EMF specification catch: make sure provided dimension object does not have more than 30 entries
40
- // if (Object.keys(CustomerDefinedDimension).length > 30) {
41
- // throw new Error(
42
- // "EMF has a limit of 30 user defined dimension keys per log"
43
- // );
44
- // }
40
+ if (Object.keys(CustomerDefinedDimension).length > 30) {
41
+ throw new Error(
42
+ "EMF has a limit of 30 user defined dimension keys per log"
43
+ );
44
+ }
45
45
  //Create new instance of Logger to use in function
46
46
  const logger = new Logger({ serviceName: "serverlessAirline" });
47
47
  //Set up Ajv instance for JSON validation
@@ -230,9 +230,26 @@ async function catalog(
230
230
  );
231
231
  }
232
232
  //clear cache after logging all cached objects to Lambda
233
- console.log("BEFORE:", cache);
233
+ console.log("BEFORE:", JSON.stringify(cache, null, 2));
234
234
  for (var member in cache) delete cache[member];
235
235
  console.log("AFTER:", cache);
236
236
  }
237
237
  }
238
- export { cache, catalog };
238
+
239
+ //If you want to manually deploy the cache without writing a catalog for it
240
+ async function deployCatalog() {
241
+ //Create a new instance of Logger
242
+ const logger = new Logger({ serviceName: "serverlessAirline" });
243
+ //Log all cached objects to Cloudwatch through Lambda
244
+ for (let i = 0; i < Object.keys(cache).length; i++) {
245
+ logger.info(
246
+ `Your EMF compliant Structured Metrics Log ${i + 1}`,
247
+ cache[Object.keys(cache)[i]]
248
+ );
249
+ }
250
+ //clear cache after logging all cached objects to Lambda
251
+ console.log("BEFORE:", JSON.stringify(cache, null, 2));
252
+ for (var member in cache) delete cache[member];
253
+ console.log("AFTER:", cache);
254
+ }
255
+ export { cache, catalog, deployCatalog };
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "cat-a-logs",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "Create & send structured logs to AWS Cloudwatch logs",
5
5
  "main": "index.js",
6
- "exports":{
6
+ "exports": {
7
7
  "./index.js": "./client/index.js"
8
8
  },
9
9
  "scripts": {