Telescope application debugging tool
- Update Telescope
- Customized data migration
- Configuration
- Data modification
- Dashboard authorization
- Filter
- Single filter
- Batch filter
- Available listeners
- Data monitoring
- Event monitoring
- Exception monitoring
- Gate monitoring
- Process Monitoring
- Log monitoring
- Email monitoring
- Model monitoring
- Message notification monitoring
- Data query monitoring
- Redis monitoring
- Request Monitor
- Schedule Monitor
- Introduction
- Installation
- ##Dashboard authorization
- Filtering ##Available monitoring
Laravel Telescope
composer require laravel/telescopeAfter installing Telescope, you can use it in Artisan
telescope:install command to configure the extension instance. After installing Telescope, you should also run the
migrate command:
php artisan telescope:install php artisan migrateUpdate TelescopeWhen updating Telescope, you should reconfigure the loaded Telescope instance:
php artisan telescope:publishInstall only in specific environmentsIf you plan to use Telescope only to assist with your local development. Telescope can be installed using the
--dev flag:
composer require laravel/telescope --devAfter running
telescope:install you should remove the ## from the
app configuration file #TelescopeServiceProvider
Service provider registration. Instead, manually register the service in the register
method of AppServiceProvider
: use Laravel\Telescope\TelescopeServiceProvider;
/**
* 注册应用服务。
*
* @return void
*/public function register(){
if ($this->app->isLocal()) {
$this->app->register(TelescopeServiceProvider::class);
}
}
Telescope::ignoreMigrations
method in theregister method of
AppServiceProvider. You can export default migrations using the
php artisan vendor:publish --tag=telescope-migrations command.
config/telescope.php
. This configuration file allows you to configure listener options, each configuration option contains a description of its purpose, so be sure to browse this file thoroughly.If desired, you can completely disable Telescope's data collection using the
enabled
'enabled' => env('TELESCOPE_ENABLED', true),
With data modifications, the telescope_entries
table can accumulate records very quickly. To mitigate this issue, you should run thetelescope:prune command every day using Artisan:
$schedule->command('telescope:prune')->daily();
By default, all data older than 24 hours will be fetched. You can use the
hours option when calling the command to determine how long Telescope data is retained. For example, the following command will delete all records created 48 hours ago: $schedule->command('telescope:prune --hours=48')->daily();
Telescope in /telescope# Display the dashboard at ##. By default, you can only access this dashboard in your
local environment. In your app/Providers/TelescopeServiceProvider.php
file, there is a gate
method. This authorization controls access to Telescope in non-local
environments. You are free to modify this permission restriction as needed for your Telescope installation and access: /**
* 註冊 Telescope Gate。
*
* 使用 Gate 决定谁可以在非本地环境中访问 Telescope。
*
* @return void
*/
protected function gate(){
Gate::define('viewTelescope', function ($user) {
return in_array($user->email, [
'taylor@laravel.com',
]);
});
}
Single item filtering
You can filter the data recorded by Telescope through the filter
callback registered in TelescopeServiceProvider
. By default, this callback logs all data in the local
environment and exceptions, process interruptions, scheduled tasks, and data in all other environments with the monitored flag:
/** * 注册应用服务。 * * @return void */ public function register(){ $this->hideSensitiveRequestDetails(); Telescope::filter(function (IncomingEntry $entry) { if ($this->app->isLocal()) { return true; } return $entry->isReportableException() || $entry->isFailedJob() || $entry->isScheduledTask() || $entry->hasMonitoredTag(); }); }
Batch filtering
While the filter
callback filters data for a single entry, you can register a callback using the filterBatch
method, This callback filters all data for a given request or console command. If the callback returns true
, all data is recorded by Telescope:
use Illuminate\Support\Collection; /** * 注册应用服务。 * * @return void */ public function register(){ $this->hideSensitiveRequestDetails(); Telescope::filterBatch(function (Collection $entries) { if ($this->app->isLocal()) { return true; } return $entries->contains(function ($entry) { return $entry->isReportableException() || $entry->isFailedJob() || $entry->isScheduledTask() || $entry->hasMonitoredTag(); }); }); }
Available listeners
When in control Telescope listeners collect application data when the platform executes commands or handles requests. You can customize the list of items to enable listening in the config/telescope.php
configuration file:
'watchers' => [ Watchers\CacheWatcher::class => true, Watchers\CommandWatcher::class => true, ... ],
Some listeners also allow you to provide additional customization options:
'watchers' => [ Watchers\QueryWatcher::class => [ 'enabled' => env('TELESCOPE_QUERY_WATCHER', true), 'slow' => 100, ], ... ],
Cache Listener
Cache listeners record data when cache keys are hit, missed, updated, and forgotten.
Command Listening
The command listener logs arguments, options, exit codes, and output whenever an Artisan command is executed. If you want to exclude certain commands from being recorded by the listener, you can specify the commands in the ignore
option of the config/telescope.php
file:
'watchers' => [ Watchers\CommandWatcher::class => [ 'enabled' => env('TELESCOPE_COMMAND_WATCHER', true), 'ignore' => ['key:generate'], ], ... ],
Data Listening
Data Listener records and displays your data variables in Telescope. When using Laravel, you can use the global dump
function to output variables. The data listener tab must be open in the browser to output variables, otherwise the listener will ignore this output.
Event Listeners
Event listeners record the payload, listener, and broadcast data for any event dispatched by the application. Event listeners ignore Laravel framework internal events.
Exception Listener
The exception listener records data and stack traces for any reportable exceptions thrown by the application.
Gate Listener
Gate listener records the data and results of your application's Gate and policy checks. If you wish to exclude certain capabilities from logging by the listener, you can specify them in the ignore_abilities
option in the config/telescope.php
file:
'watchers' => [ Watchers\GateWatcher::class => [ 'enabled' => env('TELESCOPE_GATE_WATCHER', true), 'ignore_abilities' => ['viewNova'], ], ... ],
Process Listener
The process listener records the data and status of any jobs dispatched by the application.
Log Monitor
The log monitor records log data for any log written by the application.
Mail Monitor
Mail Monitor allows you to view an in-browser preview of emails and their associated data. You can also download the email as an .eml
file.
Model monitoring
As long as the create
, updated
, of the model are scheduled restored
or deleted
event, the model observer will record the model changes. You can specify which model events should be logged via the events
option of the listener:
'watchers' => [ Watchers\ModelWatcher::class => [ 'enabled' => env('TELESCOPE_MODEL_WATCHER', true), 'events' => ['eloquent.created*', 'eloquent.updated*'], ], ... ],
Message Notification Listener
Message Notification listeners record all notifications sent by your application. If a notification triggers an email and you have mail listeners enabled, the email can also be previewed on the Mail Monitor screen.
Data Query Listener
The data query listener records the raw SQL, binding, and execution time of all queries executed by the application. The observer also marks any query slower than 100 milliseconds as slow
. You can customize the slow query threshold using the observer's slow
option:
'watchers' => [ Watchers\QueryWatcher::class => [ 'enabled' => env('TELESCOPE_QUERY_WATCHER', true), 'slow' => 50, ], ... ],
Redis listening
Redis events must be enabled for Redis listeners to function properly. You can enable Redis events by calling
Redis::enableEvents()
in theboot
method of theapp/Providers/AppServiceProvider.php
file.
The Redis listener records all Redis commands executed by your application. If you use Redis for caching, the Redis listener also logs cache commands.
Request Listener
The request listener records the request, header, session, and response data associated with any request processed by the application. You can limit the response data via the size_limit
(in KB) option:
'watchers' => [ Watchers\RequestWatcher::class => [ 'enabled' => env('TELESCOPE_REQUEST_WATCHER', true), 'size_limit' => env('TELESCOPE_RESPONSE_SIZE_LIMIT', 64), ], ... ],
Schedule listener
Schedule listener The programmer records the commands and output of any scheduled tasks run by the application.