feat(metrics): add ability to pass custom logger - #3057
Merged
Conversation
dreamorosi
commented
Sep 12, 2024
2 tasks
2 tasks
|
dreamorosi
marked this pull request as ready for review
September 27, 2024 14:12
dreamorosi
marked this pull request as draft
September 27, 2024 14:34
Contributor
Author
|
Integration tests are failing, will look into it tomorrow. |
Contributor
Author
|
Once #3292 is merged, I'll be ready to mark this as ready for review. |
dreamorosi
force-pushed
the
feat/metrics_custom_logger
branch
from
November 6, 2024 10:09
785d9ad to
652a5c5
Compare
Contributor
Author
|
Integration tests are finally passing. |
dreamorosi
marked this pull request as ready for review
November 6, 2024 16:55
|
am29d
approved these changes
Nov 7, 2024
am29d
left a comment
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or 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
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
debuglogs but fall back to the globalconsoleobject 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
consoleobject (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.