I am trying to debug what appears to be a socket error in the node.js https library environment when running in the AWS Lambda environment (Node.js 4.3). This issue only occurs highly intermittently and only under heavy load. My team has been able to reproduce the issue consistently with a load test, and we would like to enable debug logging from the https module.
I've found in the node documentation that I can enable debug logging by setting the NODE_DEBUG=https
environment variable. However, I don't believe that I can set environment variables: How can I use environmental variables on AWS Lambda?. Additionally, I don't have the ability to change the command line that Lambda uses to invoke my function.
Is there another way to create the same debug logging as setting NODE_DEBUG
?
NODE_DEBUG is used by built in util. debuglog . This is used by all nodejs builtin core modules and all the third party packages that decide to use it. DEBUG is used by debug module. So if you are using any package that is using this module for logging, then you need to use DEBUG .
Here's a monkeypatch:
const util = require('util');
let debuglog = util.debuglog;
util.debuglog = set => {
if (set === 'https') {
let pid = process.pid;
return function() {
let msg = util.format.apply(util, arguments);
console.error('%s %d: %s', set, pid, msg);
}
}
return debuglog(set);
}
// This has to occur _after_ the code above:
const https = require('https');
It basically enables debug logging for https
regardless of $NODE_DEBUG
. Easily rewritten to work for any module, tested with Node v4 and v6.
I'm not familiar with Aws Lambda, but maybe you can still export the variable in the command like below:
NODE_DEBUG=https node app.js
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With