feat(node-http-handler): passes client logger to request handler in codegen#2031
feat(node-http-handler): passes client logger to request handler in codegen#2031siddsriv wants to merge 2 commits into
Conversation
| return new hsAgent({ keepAlive, maxSockets, ...httpsAgent }); | ||
| })(), | ||
| logger, | ||
| logger: logger ?? clientLogger, |
There was a problem hiding this comment.
Handler-level logger (from NodeHttpHandlerOptions) takes precedence over the client-level logger.
| ) { | ||
| if (typeof (instanceOrOptions as any)?.handle === "function") { | ||
| // is already an instance of HttpHandler. | ||
| return instanceOrOptions as HttpHandler<any>; |
There was a problem hiding this comment.
When the user passes a pre-constructed handler instance (e.g. requestHandler: new NodeHttpHandler({...})), the client logger is not forwarded. The create() method returns the instance as-is. This is intentional, if you manually construct the handler, you own its configuration. Users who want the client logger in this case should pass logger explicitly in their NodeHttpHandler options.
| public static create( | ||
| instanceOrOptions?: HttpHandler<any> | NodeHttpHandlerOptions | Provider<NodeHttpHandlerOptions | void> | ||
| instanceOrOptions?: HttpHandler<any> | NodeHttpHandlerOptions | Provider<NodeHttpHandlerOptions | void>, | ||
| logger?: Logger |
There was a problem hiding this comment.
why isn't this in the options arg?
There was a problem hiding this comment.
instanceOrOptions can be a Provider function, not just an object, so we can't inject into that i believe. A separate param would be cleaner(?), the handler resolves precedence internally as options.logger ?? clientLogger.
There was a problem hiding this comment.
discussed elsewhere -
I don't want to have a separate arg just for the client logger. We have several request handlers and they should all receive loggers through their primary constructor argument object.
It could perhaps be done in one of the config resolvers, which at their point have reference to the partially initialized config containing both the request handler and a client-level logger.
If the request handler has an async-init config, it would look like this:
function resolveSomeConfig(previouslyResolved) {
if (previouslyResolved.requestHandler.configProvider is a promise) {
configProvider = configProvider.then(c => {
c.logger ??= previouslyResolved.logger || new LogLevel("warn");
})
}
}|
Converting to draft to discuss some design details for this one. |
Issue #, if available:
aws/aws-sdk-js-v3#6130
Description of changes:
NodeHttpHandleremits socket exhaustion and request timeout warnings viaconsole.warn, even when the user sets a custom logger on the SDK client. The client's logger and the request handler are assembled independently during client construction.NodeHttpHandler.create()and the constructor now accept an optionalclientLoggerparameter. This is used as a fallback, if the user didn't explicitly set logger in the handler's own options, the client logger is used instead.runtimeConfig.tsnow passesclientSharedValues.loggeras an argument toRequestHandler.create()Testing
Usage
Before (warning goes to console.warn):
After (warning goes to myLogger.warn):
Output:
If one or more of the packages in the
/packagesdirectory has been modified, be sureyarn changeset addhas been run and its output hasbeen committed and included in this pull request. See CONTRIBUTING.md.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.