DEV Community

RANA SAHA
RANA SAHA

Posted on

How to Set Up & Use Laravel Telescope for Debugging and Monitoring

Ever wondered what’s happening behind the scenes in your Laravel app? Laravel Telescope gives you full visibility into requests, database queries, exceptions, jobs, mail, notifications, and more—all in one elegant dashboard. Whether you’re debugging or optimizing performance, Telescope is a must-have tool for Laravel developers.


Step 1: Install Telescope
Run this Composer command in your Laravel project directory:

composer require laravel/telescope --dev
Enter fullscreen mode Exit fullscreen mode

The --dev flag ensures Telescope is installed only in your local environment.


Step 2: Publish Telescope Assets
After installation, run:

php artisan telescope:install
Enter fullscreen mode Exit fullscreen mode

Then migrate the database to create the required tables:

php artisan migrate
Enter fullscreen mode Exit fullscreen mode

Step 3: Secure Telescope in Production
Telescope should not be publicly accessible in production. Laravel allows you to define a gate to limit access:

protected function gate()
{
    Gate::define('viewTelescope', function ($user) {
        return in_array($user->email, [
            'admin@example.com',
        ]);
    });
}
Enter fullscreen mode Exit fullscreen mode

Only authorized users will be able to view Telescope if enabled in production.


Step 4: Access the Telescope Dashboard
Start your local server:

php artisan serve
Enter fullscreen mode Exit fullscreen mode

Then open Telescope in your browser:

http://localhost:8000/telescope
Enter fullscreen mode Exit fullscreen mode

You’ll see tabs like Requests, Queries, Exceptions, Logs, Mail, and more.


Step 5: Explore Telescope Features

  • Requests: Monitor incoming HTTP requests and responses
  • Exceptions: Track errors with full stack traces
  • Queries: View SQL queries and execution times
  • Jobs & Queues: Debug queued jobs and failures
  • Cache: Inspect cache hits and misses
  • Mail & Notifications: See emails and notifications sent by your app
  • Logs: Centralized log entries for easier debugging

Step 6: Manage Telescope Data
Telescope stores data in your database. To avoid it growing too large, prune old entries:

php artisan telescope:prune --hours=48

Enter fullscreen mode Exit fullscreen mode

You can also schedule pruning automatically in app/Console/Kernel.php:

protected function schedule(Schedule $schedule)
{
    $schedule->command('telescope:prune --hours=48')->daily();
}
Enter fullscreen mode Exit fullscreen mode

Conclusion

Laravel Telescope is an essential tool for Laravel developers. It helps you debug queries, track exceptions, monitor jobs, and optimize application performance. Start using it today and see exactly what’s happening inside your application.

You can also read this tutorial on my blogger website
for more Laravel guides and updates.

Top comments (0)