-
Notifications
You must be signed in to change notification settings - Fork 77
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(middleware-correlationid): added ability for custom logger #231
Conversation
@lkhari can you explain the use case here? why only add custom logger constructor in the correlation IDs middleware, that seems like a really odd thing to do. If you want to support a customer logger, wouldn't it be better to add that support directly to the logger module so that it can proxy all the requests to your customer logger? |
To be honest, the use case came from #220 PR, when I wanted to expose the log library. And I interpreted an issues that middleware-correlationId was a little too coupled to the logger. This PR is really just a first stepping stone in decoupling the two libraries and allowing other people to use their own Logger. |
The fact that they are tightly coupled is by design - in the same way that iPhone, mac and airpods are design to work great together even if they're not necessary so good with other devices. It's even in our readme |
I quite like this approach as it will allow us to attach our own loggers to the context (which is where I want them), without touching the internal logs written by powertools (which would be a right pain to modify) At DAZN, we use our own logger (not powertools) and currently have a middy middleware which effectively reproduces the logger functionality of middleware-correlation-ids by looping over all records and attaching the correct logger to them, and to the context. Being able to avoid this would be a quick win for us. I need to think about this some more, but I think trying to patch in the whole powertools-logger with a custom logger would be annoyingly complex, so limiting it to the loggers which are exposed by powertools to the application (ie, this middleware) is a good middle-ground |
@simontabor why do you think injecting a custom logger through the powertools logger would be annoyingly complex? Making that the injection point would make it work for all the middleware in this suite and not just correlation IDs. |
I can see the benefits of both sides. I like that the idea of proxy to encourage these good practices, but it could be problematic when a dev wants to use a function not exposed by our proxy-logger, which could then lead to this repo getting a lot more request for more functionality. Turning the logger into a proxy, seems a bit wrong, since it's title is Regardless of the idea to make It could be argued, from another point of view, that adding the logger to the Records, is extra functionality from the |
@lkhari
|
Sorry, my PR description was a bit lacking. The PR goal is to allow the middleware to attach a custom logger to the Records coming in from SQS, Kinesis, etc. It doesn't allow the middleware to call the customer logger but it takes in a function which allows the dev to write the way their logger is constructed. A good example is wanting to use
Once #220 is merged this PR would be a lot more clear. You are right, we can still use our own logger however we'd like, without this PR. But we are also enforcing that the users also has our logger attached to their records. Which seems like unnecessary bloat. |
Because whatever logging interface is defined by powertools will leak across the entire user's application. Basically, what @lkhari said! Let's say, for example, I want to use Winston as my logger. Powertools then decides "ok I'll let you set a logger, just give me a function which accepts However, now I'm restricted to using the proxied interface, especially when using The only real limitation that this introduces is that powertools can't write any logs internally EDIT: powertools does write some logs internally: Line 51 in e9a35c4
I think we should attach the "root" logger to the main Lambda context to further support this, ie |
What did you implement:
I've added the ability to add custom loggers to the correlationId middleware
Closes #98
Blocked by #220
How did you implement it:
I've added an optional argument for the middleware library to allow you to write your own correlation logger, with it defaulting to the powertool logger. There for not causing a breaking change.
How can we verify it:
Use the correlationId middleware library and add the constructLoggerFn with your own custom logger.
Todos:
Is this ready for review?: Yes
Is it a breaking change?: NO