-
Notifications
You must be signed in to change notification settings - Fork 146
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
Feature request: logger should write to stdout directly #747
Comments
Thanks a lot of opening this issue. We want developers to be able to send their logs to external centralised monitoring tools, and for that they need to be parsed correctly as valid JSON not only by CloudWatch. As part of the unit of work of this issue we could consider also adding a E2E tests that validate the output of the logs as valid JSON. |
We were able to come up with a fix and avoid having the prefix on the logs by overriding the global I'm working on a PR to fix this and have already applied the change, but it'll take me a while to adapt our tests to reflect the changes. You can track progress in #748. |
|
The change has been merged in #748 and will be released in the next version. |
Logger should write to stdout, and not use console
Problem statement
The powertools logger is currently outputting it's logs via
console
Logger.ts#L451. Lambda appears to use a patched version ofconsole
which prefixes the timestamp, requestId and log level. This means that a powertools logged event is output to stdout as below, which is clearly not JSON:Cloudwatch handles this OK, but other tools like the newrelic and honeycomb extensions work under the assumption that JSON logs are being sent to stdout. Honeycomb even warns against the use of console.log in their documentation.
Following the honeycomb suggestion of using
bunyan
(which does write tostdout
) I have validated (as has @dreamorosi on slack) that these prefixes can be avoided by bypassingconsole.log
.The information in these prefixes is also duplicated already in the JSON message itself, so there is no loss of querying (although some may prefer to keep these prefixes so that cloudwatch queries aren't impacted.
Summary of the feature
Update the logger to avoid the patched console.log by writing logs to stdout. This will ensure that valid JSON messages can be intercepted by lambda layers and easily forwarded on to other observability tools.
Benefits for you and the wider AWS community
This is a blocker right now to anyone using centralised logging tools like NewRelic or Honeycomb, for whom structured logs are critical to the maintenance and support.
Describe alternatives you've considered
The only alternative is to use a different logger like pino or bunyan.
Additional context
I have not been able to find the source for the lambda logger internals (presumably closed source) but have verified that it must be adding the prefixes by bypassing.
Related issues, RFCs
#646
#lambda-powertools slack discussion
The text was updated successfully, but these errors were encountered: