-
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
feat(metrics): add ability to pass custom logger #3057
Conversation
Quality Gate passedIssues Measures |
Integration tests are failing, will look into it tomorrow. |
Once #3292 is merged, I'll be ready to mark this as ready for review. |
785d9ad
to
652a5c5
Compare
Integration tests are finally passing. |
Quality Gate passedIssues Measures |
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.
Thanks for the PR, LGTM!
I checked the e2e test after main rebase they seem to be flake for the logger. Need to investiage later.
Summary
Changes
This PR adds the ability to pass a custom logger object to the Metrics utility. This is useful when you want to enable debug logs or suppress warnings emitted by the utility.
Customers have been asking for a way to silence warnings which is not possible today due to Node.js not having a standard logging library similar to other languages such as Python. To go around the issue, I decided to follow a pattern used by other Node.js libraries in the ecosystem such as AWS SDK for JavaScript v3 and AWS X-Ray SDK for Node.js, which accept a generic "logger" class.
When the logger class is present, these libraries start emitting debug logs and other telemetry. In our case we'll follow the same pattern for
debug
logs but fall back to the globalconsole
object for warnings since we always want to emit them.Likewise, in the case of Metrics, the actual EMF blobs will always bypass any custom logger passed by customer and go to stdout. I deliberately choose to go this route to avoid compatibility issues with 3rd party loggers and decrease the risk of data loss.
While I hope customers will use this feature with our Logger, the interface for the logger object is as generic as possible and allows 3rd party loggers or even the Node.js
console
object (aka global console).For now I opted for documenting this feature only in the API docs and not in the main docs as I want to soft-launch it before publicising it more. In future releases we'll work on adding some debug logs similar to what Powertools for AWS Lambda (Python) does, which was something we couldn't do up until now.
Once that work is done and this pattern is applied across more utilities we'll update the docs as well. This will also give us some time to learn how customers use the feature.
Example
This is the DX of how customers would specify a custom logger, when using the Powertools for AWS one this gives the added benefit of controlling the log level and silencing warnings as needed.
This pattern is also useful for unit testing, as it essentially allows dependency injection as well.
Issue number: closes #2036
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.