-
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): merge child logger options correctly #1178
fix(logger): merge child logger options correctly #1178
Conversation
Hey, @dreamorosi I have some questions to discuss. Could you help me figure this out, please?
|
Definitely, and thank you for the PR 👍.
I would say yes, just like all other attributes set by other means. If later on there's demand to have this behavior customizable we'll add an option to
Go with
If I understand the point correctly, and read it in the context of your current implementation, I think it should stay as not optional and default to
The command would be While we still have |
Ok, I'll make
I thought not to include property in instances initialized without options or with an empty object. I tested it and decided, that not having an empty object in some instances of the Logger class is not worth the changes needed. One other thing not connected to this PR: here #1153
If I import Thanks for the fast responses! |
Nice, sounds sensible.
Agreed.
That's our bad. We should clarify this better in the You should be able to fix this by running From the way that Hope this clarifies it! |
Hey @dreamorosi. I found a way to get rid of It's ready to review. If more tests are needed, let me know. |
packages/logger/src/Logger.ts
Outdated
const parentsPersistentLogAttributes = this.getPersistentLogAttributes(); | ||
childLogger.addPersistentLogAttributes(parentsPersistentLogAttributes); | ||
const childPowertoolsLogData = childLogger.getPowertoolLogData(); | ||
childLogger.addToPowertoolLogData(merge({}, parentsPowertoolsLogData, childPowertoolsLogData)); |
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.
@shdq: question: why do we merge and use the parentsPowertoolsLogData
twice? Maybe worth documenting with a comment (inside the method, so we don't expose it in the docstring)
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.
Constructor doesn't use lambdaContext
, so in line 211 it extracts context (if any) and merges it with childPowertoolsLogData
to not overwrite the child's options. Thanks for the question, I went through the code again and refactored it, removed extra work, and made it more readable – no comments needed:
const parentsLambdaContext = parentsPowertoolsLogData?.lambdaContext;
if (parentsLambdaContext) {
childLogger.addToPowertoolLogData({ lambdaContext: parentsLambdaContext });
}
I will push it when I fix the test coverage.
On Thursday I'm planning on making a new release, I'm mentioning this just in case you'd like this PR to be included - if not it'll be guaranteed to be in the next one in ~2 weeks |
I think this PR is finished and will be in the next release 🤞 |
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.
Thank you @shdq for working on this, appreciate the effort as usual.
Integration tests were passing: https://github.com/awslabs/aws-lambda-powertools-typescript/actions/runs/3533218456
Description of your changes
Initial options (if any) now store in the
initLogger
class property when an instance of Logger creates. When a child creates out of the parent,createChild
uses the parents' initial options to create a new instance of Logger.lodash.clonedeep
dependency is no longer neededHow to verify this change
Related issues, RFCs
Issue number: #1163
PR status
Is this ready for review?: NO
Is it a breaking change?: NO
Checklist
Breaking change checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.