Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[FrameworkBundle] revert implementing LoggerAwareInterface in HTTP client decorators#54674

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:7.1fromxabbuh:pr-54668
May 2, 2024

Conversation

@xabbuh
Copy link
Member

QA
Branch?7.1
Bug fix?no
New feature?no
Deprecations?no
Issues
LicenseMIT

* @author Jérémy Derussé <jeremy@derusse.com>
*/
class RetryableHttpClientimplements HttpClientInterface,LoggerAwareInterface,ResetInterface
class RetryableHttpClientimplements HttpClientInterface, ResetInterface
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Implementing theLoggerAwareInterface when the constructor already receives a logger doesn't look reasonable to me.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I also wonder if we shouldn't change the other decorators to let them optionally receive a logger in their constructor too instead of implementing theLoggerAwareInterface

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

doing so would also allow us to revert thecomposer.json changes

@xabbuhxabbuhforce-pushed thepr-54668 branch 2 times, most recently frombbc39d2 to3d39484CompareApril 19, 2024 11:51
$this->logger =$logger;

if (null !==$logger &&$this->clientinstanceof LoggerAwareInterface) {
$this->client->setLogger($logger);
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I am not convinced that a decorator should actually modify the decorated HTTP client this way. IMO setting the logger is the user's responsibility when constructing the client.

@nicolas-grekas
Copy link
Member

Looking at your comments here, I wonder if we should keep#54668 or not?
Maybe@yann-eugone can tell use how he wires the client so that we understant why adding LoggerAwareInterface helps?
I'm not keen on the bump in composer.json, it'd prefer not doing it.

@yann-eugone
Copy link
Contributor

yann-eugone commentedApr 22, 2024
edited
Loading

Sure,

On that project, constructing anHttpClientInterface is a thing that is done at runtime, because it all depend on configuration (what service you are trying to call)

finalclass HttpClientFactory{publicfunction__construct(privatereadonlyHttpClientInterface$http,    ) {    }publicfunctioncreate(Config$config,LoggerInterface$logger):HttpClientInterface    {$client =match (...) {            Config::A =>$this->clientA(),            Config::B =>$this->clientB(),        };if ($clientinstanceof LoggerAwareInterface) {$client->setLogger($logger);        }return$client;    }privatefunctionclientA():HttpClientInterface    {return$this->http->withOptions([            ...        ]);    }privatefunctionclientB():HttpClientInterface    {return$this->http->withOptions([            ...        ]);    }}

I'm usingSymfony\Contracts\HttpClient\HttpClientInterface::withOptions because it's way safer for unit testing to clone a client provided from a constructor than having to build from the ground.

As you can see, the$logger is provided in the factory method, because each feature has it's own logger instance, but they all share dependency onHttpClientFactory

#[WithMonologChannel('feature1')]finalclass Feature1{publicfunction__construct(privatereadonlyHttpClientFactory$httpClientFactory,privatereadonlyLoggerInterface$logger,    ) {    }publicfunctionmethod(Config$config):void    {$http =$this->httpClientFactory->create($config,$this->logger);...    }}#[WithMonologChannel('feature2')]finalclass Feature2{publicfunction__construct(privatereadonlyHttpClientFactory$httpClientFactory,privatereadonlyLoggerInterface$logger,    ) {    }publicfunctionmethod(Config$config):void    {$http =$this->httpClientFactory->create($config,$this->logger);...    }}

I've only proposed addingLoggerAwareInterface because I saw that actual clients already implemented it, so I believed it was just about someone forgetting to add it everywhere.

@OskarStark

This comment was marked as outdated.

@OskarStarkOskarStark changed the title[FrameworkBundle] wire setLogger() calls for registered HTTP clients[FrameworkBundle] wiresetLogger() calls for registered HTTP clientsApr 22, 2024
@yann-eugone

This comment was marked as outdated.

@xabbuh
Copy link
MemberAuthor

What about supporting passing the logger towithOptions() instead? This could look something like this in your factory then:

privatefunctionclientA(LoggerInterface$logger):HttpClientInterface{return$this->http->withOptions(['extra' => ['logger' =>$logger,        ],// ...    ]);}
OskarStark reacted with thumbs up emoji

@nicolas-grekas
Copy link
Member

I wonder if we need this PR at all: to me, the actual http client that does log should already have the logger wired. Did you check this aspect?

@xabbuhxabbuhforce-pushed thepr-54668 branch 2 times, most recently from8ae7a05 to436bf31CompareApril 30, 2024 09:10
@xabbuhxabbuh changed the title[FrameworkBundle] wiresetLogger() calls for registered HTTP clients[HttpClient] revert implementing LoggerAwareInterface in HTTP client decoratorsApr 30, 2024
@xabbuh
Copy link
MemberAuthor

to me, the actual http client that does log should already have the logger wired

I agree with this reasoning. That's why I suggest to revert implementing theLoggerAwareInterface in HTTP client decorators.

@yann-eugone
Copy link
Contributor

I don't have any opinion on this honestly
But why removingsetLogger on decorated clients, but not on actual ones ?

@xabbuh
Copy link
MemberAuthor

The actual clients do use the logger themselves. They do not use this property to configure another client. We can argue if using the interface was the right decision back when we introduced it, but that’s a different topic.

@xabbuhxabbuh added the ❄️ Feature FreezeImportant Pull Requests to finish before the next Symfony "feature freeze" labelMay 2, 2024
@carsonbotcarsonbot changed the title[HttpClient] revert implementing LoggerAwareInterface in HTTP client decorators[FrameworkBundle] revert implementing LoggerAwareInterface in HTTP client decoratorsMay 2, 2024
Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

🚀

We could even deprecate existing setLogger proxies.

@fabpot
Copy link
Member

Thank you@xabbuh.

@xabbuh
Copy link
MemberAuthor

We could even deprecate existing setLogger proxies.

see#54806

fabpot added a commit that referenced this pull requestMay 2, 2024
…ing clients (xabbuh)This PR was merged into the 7.1 branch.Discussion----------[HttpClient]  deprecate setLogger() methods of decorating clients| Q             | A| ------------- | ---| Branch?       | 7.1| Bug fix?      | no| New feature?  | no| Deprecations? | yes| Issues        |Fix#54674 (review)| License       | MITCommits-------9d95152 deprecate setLogger() methods of decorating clients
@fabpotfabpot mentioned this pull requestMay 2, 2024
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

Assignees

No one assigned

Labels

FrameworkBundle❄️ Feature FreezeImportant Pull Requests to finish before the next Symfony "feature freeze"Status: Reviewed

Projects

None yet

Milestone

7.1

Development

Successfully merging this pull request may close these issues.

6 participants

@xabbuh@nicolas-grekas@yann-eugone@OskarStark@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp