-
Notifications
You must be signed in to change notification settings - Fork 138
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
Draft
dreamorosi
wants to merge
6
commits into
main
Choose a base branch
from
feat/metrics_custom_logger
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
+66
−79
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
boring-cyborg
bot
added
commons
This item relates to the Commons Utility
metrics
This item relates to the Metrics Utility
tests
PRs that add or change tests
labels
Sep 12, 2024
github-actions
bot
added
the
feature
PRs that introduce new features or minor changes
label
Sep 12, 2024
dreamorosi
commented
Sep 12, 2024
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.
This file was a leftover from a previous PR which wasn't supposed to be committed.
2 tasks
2 tasks
Quality Gate passedIssues Measures |
Integration tests are failing, will look into it tomorrow. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.