Using Laravel Telescope For Debugging

Spread the word! Share with your fellow developers.

Laravel Telescope is an open source debugging tool by Laravel. It is open source, free and available on Github. You can install it by adding it as a Composer dependency.

What is Laravel Telescope?

Telescope is a debugging tool which is a combination of different watchers for incoming requests on your application such as HTTP Request, Command Line Requests, Scheduler or Queue.

These watchers catch all type of information about these requests like database queries, query execution time, events fired and much more.

Installing Laravel Telescope

Before installing Telescope, you need to have Laravel installed. If you want to create a new application you can run below command in your terminal and it will create a new Laravel project.

composer create-project laravel/laravel Telescope

To install Laravel Telescope, run below command:

composer require laravel/telescope --dev

You can use --dev tag to install it as a dev dependency or you can install it without this tag.

After the installation is set and done, you can move to prepare the assets, config files, and database by running:

php artisan telescope:install
php artisan migrate

Configuring Laravel Telescope

Right after the installation, you can open the route /telescope and you will be presented with Telescope like below:

Laravel Telescope
Laravel Telescope

You can change the route in the config/telescope.php file. This file allows you to configure Laravel Telescope. Most important options are:

path

This is the path within your application which will allow you to access telescope. The default value is telescope.

driver

This is where Telescope will store the data. The default value is database.

storage

This will determine which database connection to use. It’ll use your default database connection.

limit

This will determine how much data Telescope will store for everything you will debug. The default value is 100.

Restricting Access to Telescope

In your local environment, any user can access the Telescope. Let’s say in the production environment you want to restrict the access for selected users. To achieve this, go to app/Providers/TelescopeServiceProvider.php file and find the gate function.

/**
 * Register the Telescope gate.
 *
 * This gate determines who can access Telescope in non-local environments.
 *
 * @return void
 */
protected function gate()
{
    Gate::define('viewTelescope', function ($user) {
        return in_array($user->email, [
            //
        ]);
    });
}

You can add a list of emails. Users with this email will have access to Telescope.

Features of Laravel Telescope

The telescope comes with multiple options, where you can monitor the processing of almost everything. I mostly use the below tabs to look after the performance of my application.

Requests

This tab contains information about all incoming HTTP requests to your application.

Laravel Telescope - Requests
Laravel Telescope – Requests

Commands

The command tab shows all the executed commands as well as their exit code. You can as well see arguments, options and related items for those commands.

Laravel Telescope - Commands
Laravel Telescope – Commands

Exceptions

Logs all exceptions and allows you to inspect each. This will show you similar data to the other tabs, like hostname, type, request, tags, authenticated user.

Laravel Telescope - Exceptions
Laravel Telescope – Exceptions

Logs

The logs tab shows you the basic log message, level, and when it happened for all log items.

Laravel Telescope - Logs
Laravel Telescope – Logs

Queries

List of all your DB queries–like the debug bar. How long they took, jump in and view the full query, which requests triggered it, etc. Nice formatted view.

Laravel Telescope - Queries
Laravel Telescope – Queries

Models

You can see create, update, delete events; shows the changes that were made, etc.

Laravel Telescope - Models
Laravel Telescope – Models
Laravel Telescope Model Details
Laravel Telescope Model Details

Mail

Shows a list of all emails that were sent; who the recipients are; when it happened; whether it’s queued and then when the queue kicks it out. Can see the email subject, and when you dig into it you also see a preview of the email like MailTrap.

Laravel Telescope - Mail
Laravel Telescope – Mail
Laravel Telescope - Mail Details
Laravel Telescope – Mail Details

Notifications

Shows all notifications, what type they were, etc. No previews since some notifications aren’t preview-able, but if it’s a mail notification you’ll also see it there. If notification was queued, you can also see it under the Jobs section on the request.

Laravel Telescope - Notifications
Laravel Telescope – Notifications

There are also tabs for Schedule, Jobs,, Dumps, Gates, Events, Cache and Redis. All these tabs provide very detailed information about all processings.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*
*

This site uses Akismet to reduce spam. Learn how your comment data is processed.