Example of what the output looks like in CloudWatch
hello-josh opened this issue · 2 comments
I need more information in my logs to track down specific invocations of my lambda functions. Do you have a screenshot of what the log messages looks like in CloudWatch using your library? I'm looking to add a know ID for correlation of log messages and this looks like it may suffice.
@TRII This is something that would be suited to be include in the meta
object. I may end up adding the ability to include additional tags for each log, but I haven't found a reason for it as it can be handled with meta. I've attached a couple of screenshots below with certain information redacted:
log.info('Running updateProducts');
// err comes from node-mysql in the example above.
// meta is the event data from Lambda (API Gateway in the example)
log.error(err, { event });
In your case, you could use tags to store an invocation ID for all logs globally, so it applies to all future logged messages:
const log = require('lambda-log');
exports.handler = function(event, context, callback) {
// Add the "awsRequestId" as a tag, can be anything you want though to distinguish invocations
log.config.tags.push(context.awsRequestId);
// ...
log.info('Some information message');
//=> { msg: 'Some information message', _tags: ["log", "info", "AWSREQUESTID"] }
};
You can do the same with with global metadata also if that would be better suited than the tags. Metadata will make using CloudWatch Filter Queries easier:
const log = require('lambda-log');
exports.handler = function(event, context, callback) {
// Add the "awsRequestId" in metadata, can be anything you want though to distinguish invocations
log.config.meta.invokeID = context.awsRequestId;
// ...
log.info('Some information message');
//=> { msg: 'Some information message', invokeID: 'AWSREQUESTID', _tags: ["log", "info"] }
};
Filter Query with Tags:
Replace AWSREQUESTID with the actual request ID.
{ $._tags[2] = "AWSREQUESTID" }
Filter Query with Metadata:
Replace AWSREQUESTID with the actual request ID.
{ $.invokeID = "AWSREQUESTID" }
I'm going to close this issue for now, but feel free to let me know if you have any questions!
Thanks! This helps a lot