Mon Dec 03 2018

Laravel Telescope and its utility

Programming1342 views

Laravel Telescope and its utility

Laravel Telescope is a new application debugging assistant from Laravel. It's open source, free on GitHub. Built by Mohamed Said and Taylor Otwell.

Laravel Telescope is open-source software licensed under the MIT license. Telescope provides insight into the requests coming into your application, exceptions, log entries, database queries, queued jobs, mail, notifications, cache operations, scheduled tasks, variable dumps and more. The telescope makes a wonderful companion to your local Laravel development environment.

Laravel Telescope utilities

You'll pull it into your applications as a third-party dependency via Composer.

After publishing Telescope's assets, its primary configuration file will be located at config/telescope.php. This configuration file allows you to configure your watcher options and each configuration option includes a description of its purpose, so be sure to thoroughly explore this file.

Data Pruning

Without pruning, the telescope_entries table can accumulate records very quickly. To mitigate this, you should schedule the telescope:prune Artisan command to run daily.

By default, all entries older than 24 hours will be pruned. You may use the "hours" option when calling the command to determine how long to retain Telescope data.

Dashboard authorization

Telescope exposes a dashboard at /telescope. By default, you will only be able to access this dashboard in the local environment. Within your app/Providers/TelescopeServiceProvider.php file, there is a gate method. This authorization gate controls access to Telescope in non-local environments. You are free to modify this gate as needed to restrict access to your Telescope installation.

Here’s the list of tabs mention that you can inspect in the Telescope UI:

(HTTP) Requests

This tab allows you to see all of the HTTP requests that come into your application. You'll be able to inspect all the HTTP requests and all sorts of useful info about each request.

Commands

The commands tab lists all the commands that have been run and their exit codes. When you dive in you can also see all of their arguments, options, and related items.

Schedule

Lists the scheduled tasks that have been run. On each task detail page, see all of their scheduling information like their cron schedule (e.g. * * * * *).

Jobs

The jobs tab lists out all of the jobs that have run or all running. It's similar to Horizon, but Horizon is Redis-only and isn't just a UI, and it also interacts with how your queue workers are running. Telescope, on the other hand, is just a UI, but it also works for all queue drivers. On the jobs list page, you'll be able to see the job name, which queue and connection it ran on, its status, and when it happened.

On the job detail page, you'll be able to see all of that data and more: hostname, job's fully-qualified class name, connection, queue, # of tries, timeout, tags.

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.

Logs

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

Dump screen

If you use the dump() method in your code, in Telescope, you'll see the dumps in Telescope but not your actual application. This gives you dd() style output of your data without it messing up your normal page load. Each dump also links to the request which generated it. If you leave the dump screen, all of a sudden your dumps show up in your browser again.

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.

Models

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

Events

Shows a list of all your events. You can see which events were broadcast with a tag; see a list of all listeners and dig into which called.

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. Can even download the raw .eml file and open it in your client of choice.

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. Lots of angles to get much of this data.

Cache

Shows cache hits and misses abd updates etc. Shows the key, the data, when it expires, can see the request that triggered it and also on the request page you can see all the cache hits/misses for that request.

Redis

It's similar to a cache. How long they took, when it happened, which request initiated, etc.


 

Telescope can run locally and on production and has built-in authorization and tools for protecting private data. It provides access to similar data from multiple different angles, has a bevy of configuration options, and allows for robust tagging and filtering. Consider putting it on a separate database.

Taylor mentioned on Twitter later you can add filters to ensure private data doesn't get logged.

You can share your experiences with us in the comments section. Thank you!

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.