Skip to content

Instantly share code, notes, and snippets.

@danilopinotti
Last active October 6, 2022 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danilopinotti/874afea1271106959c13a055720e3ca6 to your computer and use it in GitHub Desktop.
Save danilopinotti/874afea1271106959c13a055720e3ca6 to your computer and use it in GitHub Desktop.
Show the Transfer Time in Client Request URI in Telescope
<?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),
]));
}
}
<?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