Laravel Telescope is an elegant debugging and monitoring tool for Laravel applications. It provides deep insights into requests, exceptions, queries, jobs, and more. This guide will walk you through installing, configuring, and utilizing Laravel Telescope to improve your application’s observability. You can install it with your VPS.

Prerequisitesыук

Before setting up Telescope, ensure you have the following:

  • A Laravel application (version 6.x or higher recommended)
  • PHP 7.3 or later
  • Composer installed on your machine

Step 1: Installing Laravel Telescope

To install Laravel Telescope, run the following command via Composer:

composer require laravel/telescope

Once the installation is complete, publish the Telescope service provider and assets using:

php artisan telescope:install

Finally, migrate the necessary database tables:

php artisan migrate

Step 2: Configuring Telescope

After installation, Telescope provides a configuration file located at config/telescope.php. You can customize the settings as needed.

Authorization

By default, Telescope is only accessible in the local environment. If you want to allow access in other environments, modify the gate method in App\Providers\TelescopeServiceProvider:

use Laravel\Telescope\Telescope;
use Laravel\Telescope\TelescopeApplicationServiceProvider;

class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
{
protected function gate()
{
Gate::define('viewTelescope', function ($user) {
return in_array($user->email, [
'admin@example.com',
]);
});
}
}

Data Retention

By default, Telescope keeps logs for 24 hours. You can adjust this in the config/telescope.php file:

'retain_hours' => 48,

Route Configuration

Telescope’s dashboard is accessible via /telescope. If you want to customize this path, update your config/telescope.php file:

'path' => 'monitoring',

Now, Telescope will be available at /monitoring instead of /telescope.

Step 3: Using Telescope

Once configured, start your Laravel application and visit yourdomain.com/telescope (or your customized path). You will see:

  • Requests: Monitors incoming requests and their response times.
  • Exceptions: Lists all errors and stack traces.
  • Queries: Displays executed SQL queries.
  • Jobs: Monitors queued jobs and their statuses.
  • Events: Logs Laravel events.

Step 4: Deploying Telescope to Production

While Telescope is useful in development, it is not recommended for production due to performance overhead. However, if you need to deploy it in production, you can use the TELESCOPE_ENABLED environment variable:

TELESCOPE_ENABLED=true

Additionally, schedule a command to clear logs periodically to prevent excessive database growth:

php artisan telescope:prune --hours=24

You can automate this by adding a scheduled task in app/Console/Kernel.php:

$schedule->command('telescope:prune --hours=24')->daily();

Conclusion

Laravel Telescope is a powerful tool that enhances debugging and monitoring in Laravel applications. By installing and configuring it properly, you gain valuable insights into your application’s performance, queries, exceptions, and background jobs.