-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to import console
module
#130
Comments
Thanks for the detailed report! Appreciate it!
In it's current state, console is only available globally and will only emit logs to stdout and errors to stderr. Can the customer work around the issue by providing a shim for the console module (during bundling) which simply forwards to |
Hi @richarddavison, thanks for the quick reply. As it stands we (Powertools) rely on instantiating our own In Node.js managed runtimes AWS Lambda patches the object to inject request specific info into logs (i.e. request ID and timestamp) as well as to offer features like Advanced Logging Control. Using the global object yields logs that look like this:
But our customers, including those who process their logs outside of CloudWatch, have requested that we emit logs like this:
So in response to this requirement we implemented this feature almost 2 years ago (aws-powertools/powertools-lambda-typescript#747). I understand that at least for now the |
Ah I see, thanks for the clarification. In LLRT we don't patch the console object from JS, but do it in rust. There is a special Line 584 in ee750d1
I see a couple of paths forward here:
|
Thanks for the clear answer. Given the scope of the project, I think the first option with a simpler implementation would be the best for us, but I understand we are not the only stakeholders here. From a strictly Lambda-specific point of view, having working read/write streams for logs is not really needed, so having a simple |
What is the recommendation to polyfill missing APIs like |
both console and URL are available in global scope: See here for examples: Line 99 in b01b7aa
There are a few browser specific APIs not implemented: |
I can relate, it is what I do to workaround the diff --git a/lib/Logger.js b/lib/Logger.js
index c08d5a871ff20a7d3cbd9c387747761a85af25b9..a4e1bf90fa52dc5b0e1874637ba34abaab0a902a 100644
--- a/lib/Logger.js
+++ b/lib/Logger.js
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
const node_crypto_1 = require("node:crypto");
-const node_console_1 = require("node:console");
+// const node_console_1 = require("node:console");
const node_util_1 = require("node:util");
const commons_1 = require("@aws-lambda-powertools/commons");
const formatter_1 = require("./formatter");
@@ -692,15 +692,15 @@ class Logger extends commons_1.Utility {
* @returns {void}
*/
setConsole() {
- if (!this.getEnvVarsService().isDevMode()) {
- this.console = new node_console_1.Console({
- stdout: process.stdout,
- stderr: process.stderr,
- });
- }
- else {
+ // if (!this.getEnvVarsService().isDevMode()) {
+ // this.console = new node_console_1.Console({
+ // stdout: process.stdout,
+ // stderr: process.stderr,
+ // });
+ // }
+ // else {
this.console = console;
- }
+ // }
}
/**
* Sets the Logger's customer config service instance, which will be used |
Implemented :
but using the simpler implementation that differs from Node.js for now. This fixes the console issue but there are issues with node:crypto that I will look at next (ref #294) |
Hi, we have received a report from a customer that LLRT is not compatible with Powertools for AWS Lambda (TypeScript) (aws-powertools/powertools-lambda-typescript#2050.
From an initial test we were able to narrow down the issue to the usage of the
console
module. Below a code snippet that results in an exception:Full error below:
The
console
module is listed as supported in the compatibility matrix in your readme but doesn't appear in the API docs document.Any chance that you could confirm whether the module is expected to work? If not, we'd like to raise a feature request for it to be eventually implemented on behalf of this customer.
The text was updated successfully, but these errors were encountered: