Last active
October 6, 2022 16:49
-
-
Save danilopinotti/874afea1271106959c13a055720e3ca6 to your computer and use it in GitHub Desktop.
Show the Transfer Time in Client Request URI in Telescope
This file contains 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
<?php | |
namespace App\Services\Telescope\Watchers; | |
use Illuminate\Http\Client\Events\ResponseReceived; | |
use Laravel\Telescope\IncomingEntry; | |
use Laravel\Telescope\Watchers\ClientRequestWatcher as BaseWatcher; | |
use Laravel\Telescope\Telescope; | |
class ClientRequestWatcher extends BaseWatcher | |
{ | |
/** | |
* Record a HTTP Client response. | |
* | |
* @param \Illuminate\Http\Client\Events\ResponseReceived $event | |
* @return void | |
*/ | |
public function recordResponse(ResponseReceived $event) | |
{ | |
if (!Telescope::isRecording()) { | |
return; | |
} | |
$uri = sprintf( | |
"(%.2fs)\n%s", | |
$event->response->transferStats->getTransferTime(), | |
$event->request->url() | |
); | |
Telescope::recordClientRequest(IncomingEntry::make([ | |
'method' => $event->request->method(), | |
'uri' => $uri, | |
'headers' => $this->headers($event->request->headers()), | |
'payload' => $this->payload($this->input($event->request)), | |
'response_status' => $event->response->status(), | |
'response_headers' => $this->headers($event->response->headers()), | |
'response' => $this->response($event->response), | |
])); | |
} | |
} |
This file contains 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
<?php | |
namespace App\Providers; | |
use Laravel\Telescope\TelescopeApplicationServiceProvider; | |
class TelescopeServiceProvider extends TelescopeApplicationServiceProvider | |
{ | |
/** | |
* Register any application services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
$this->app->bind( | |
\Laravel\Telescope\Watchers\ClientRequestWatcher::class, | |
\App\Services\Telescope\Watchers\ClientRequestWatcher::class | |
); | |
// ... | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment