diff options
author | Robin Appelman <robin@icewind.nl> | 2023-05-09 17:15:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-09 17:15:27 +0200 |
commit | 904fdf3aa3e55ec61943178e1fe28b0f89f8ef4f (patch) | |
tree | eb9b0c16708a5bff1e173529b271cc60d49542bf /lib/private | |
parent | 416f632280a4eccc53e09c691ae0cfbc66c0ffd8 (diff) | |
parent | e7ab30f5d8da574979f4c5b233f0cbd6827ecd90 (diff) | |
download | nextcloud-server-904fdf3aa3e55ec61943178e1fe28b0f89f8ef4f.tar.gz nextcloud-server-904fdf3aa3e55ec61943178e1fe28b0f89f8ef4f.zip |
Merge pull request #37838 from nextcloud/event-logger-http
log performance events for http requests
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Http/Client/ClientService.php | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/private/Http/Client/ClientService.php b/lib/private/Http/Client/ClientService.php index bbc2330176f..d0640680124 100644 --- a/lib/private/Http/Client/ClientService.php +++ b/lib/private/Http/Client/ClientService.php @@ -29,11 +29,14 @@ namespace OC\Http\Client; use GuzzleHttp\Client as GuzzleClient; use GuzzleHttp\HandlerStack; use GuzzleHttp\Handler\CurlHandler; +use GuzzleHttp\Middleware; +use OCP\Diagnostics\IEventLogger; use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; use OCP\ICertificateManager; use OCP\IConfig; use OCP\Security\IRemoteHostValidator; +use Psr\Http\Message\RequestInterface; /** * Class ClientService @@ -48,15 +51,20 @@ class ClientService implements IClientService { /** @var DnsPinMiddleware */ private $dnsPinMiddleware; private IRemoteHostValidator $remoteHostValidator; + private IEventLogger $eventLogger; - public function __construct(IConfig $config, - ICertificateManager $certificateManager, - DnsPinMiddleware $dnsPinMiddleware, - IRemoteHostValidator $remoteHostValidator) { + public function __construct( + IConfig $config, + ICertificateManager $certificateManager, + DnsPinMiddleware $dnsPinMiddleware, + IRemoteHostValidator $remoteHostValidator, + IEventLogger $eventLogger, + ) { $this->config = $config; $this->certificateManager = $certificateManager; $this->dnsPinMiddleware = $dnsPinMiddleware; $this->remoteHostValidator = $remoteHostValidator; + $this->eventLogger = $eventLogger; } /** @@ -66,6 +74,11 @@ class ClientService implements IClientService { $handler = new CurlHandler(); $stack = HandlerStack::create($handler); $stack->push($this->dnsPinMiddleware->addDnsPinning()); + $stack->push(Middleware::tap(function (RequestInterface $request) { + $this->eventLogger->start('http:request', $request->getMethod() . " request to " . $request->getRequestTarget()); + }, function () { + $this->eventLogger->end('http:request'); + }), 'event logger'); $client = new GuzzleClient(['handler' => $stack]); |