-
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
fix(logger): POWERTOOLS_LOGGER_LOG_EVENT precedence is respected #1015
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, minor suggestion , can be ignored
if (options) { | ||
logger.logEventIfEnabled(request.event, options.logEvent); | ||
} | ||
const logEvent = options ? options.hasOwnProperty('logEvent') ? options.logEvent : undefined : undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is Node 12 support actually needed? Active support for it ended over a year and a half ago and even extended security support for it ended 2 months ago. It's now officially past EOL.
That said, I don't have insight into how many Node12 Lambdas are still running, so maybe supporting existing functions makes it worthwhile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @bilalq, yes.
For the time being we are committed to support Node.js 12.x since AWS Lambda still supports that runtime.
So far, and aside from these minor changes in some lines, it hasn't been a blocker for us, so we still see value in allowing those customers who might have not migrated to newer and actively maintained runtimes to use the Powertools utilities.
📊 Package size report 0.4%↑
🤖 This report was automatically generated by pkg-size-action |
if (options) { | ||
logger.logEventIfEnabled(request.event, options.logEvent); | ||
} | ||
const logEvent = options ? options.hasOwnProperty('logEvent') ? options.logEvent : undefined : undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saragerion: a comment on the e2e test I added like you asked. Before this PR we had 3 stacks for e2e tests & Logger:
Each stack defines one single Lambda function with some env vars and some params in the constructor / middleware. In order to test this case the function would need the following configs:
I have considered adding this test case to the middleware one but this is not possible because the function passes the Likewise I have also considered adding it to the decorator one but this is also not compatible as that function/stack sets log level equal to In order to add this I had to add a new and dedicated stack + function. Considering that the feature in itself is already being tested in the e2e (via middleware param) and that this PR introduces unit test cases that specifically target this behaviour (env variable but not middleware/decorator param), are we okay with having a new stack / function that makes the e2e tests longer? This is not a big issue but I wanted to point this out & document it as it kind of breaks the neat organization of the test cases we had in the logger. |
📊 Package size report 0.4%↑
🤖 This report was automatically generated by pkg-size-action |
@@ -0,0 +1,16 @@ | |||
import { injectLambdaContext, Logger } from '../../src'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) missing Copyright header?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of the functions in that group of e2e tests has the copyright header, should I add it?
📊 Package size report 0.4%↑
🤖 This report was automatically generated by pkg-size-action |
* fix: POWERTOOLS_LOGGER_LOG_EVENT precedence is respected * fix: decorator logic * chore: added unit test cases for decorator * chore: added e2e test cases * chore: address review comments
Description of your changes
This PR aims at fixing a bug that was identified by @saragerion in the logger. In v0.11.0 we released a feature that allows to log the event parameter of a function handler. This is an opt-in feature that can be enabled by users by either passing a
logEvent
parameter equal to true in the middleware/decorator or by setting aPOWERTOOLS_LOGGER_LOG_EVENT
environment variable also equal to true. In the current iteration of the utility only the first method works.I was able to reproduce the issue in my own tests.
There were two separate issues that contributed to this bug:
When deciding on whether to log the event or not a function named
logEventIfEnabled
is called. This function takes in account - and gives precedence to - the parameter passed in the middleware/decorator but also checks the value of thelogEvent
property that is part of the currentLogger
class. This property is set tofalse
by default (as documented). That same property should be set totrue
upon class instantiation and as a part of thesetOptions
lifecycle if thePOWERTOOLS_LOGGER_LOG_EVENT
env var is present & with a truthy value, but this never happened.The second issue, perhaps minor or intended (would appreciate feedback if that was the case) was that both middleware and decorator called the
logEventIfEnabled
function mentioned above only when anoptions
parameter is passed to the middleware/decorator. For example:Even fixing the logic as described previously, the code below still doesn't work because since the
injectLambdaContext
doesn't have a second parameter (options
), the Logger class never checks if the log event feature was enabled via env var:To make it work, developers would have had to pass an empty object (or an object with other configs like
clearState
):The same applies to the decorator usage.
Since we cannot rely on the presence of other configs (i.e.
clearState
) we shouldn't force devs to pass an empty object for the env var config to be evaluated.How to verify this change
See additional unit test cases that were added.
Related issues, RFCs
N/A
PR status
Is this ready for review?: YES
Is it a breaking change?: NO
Checklist
Breaking change checklist
N/A
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.