Next article

Introducing Gatsby for building websites using WordPress and ReactJS

Websites are like virtual gateways to your business profitability. Businesses are extremely cautious while deciding to develop one that has the potential to accelerate opportunity....

Smart Monitoring of Laravel Application using Telescope

Smart monitoring of Laravel application using Telescope

Considering the immense popularity or Laravel application among developers with the exemplary features it offers to the users. Every user is always looking for smarter ways to create websites and seeking new innovations in Laravel technology that will allow users to deliver better end results. So, we found one of the most popular frameworks Laravel has advanced its features by adding a smart monitoring solution in the application which is named as Telescope.

Table of Content
  1. How will customers benefit from Laravel Telescope
  2. Understanding the telescope
  3. Restricting access to telescope
  4. Conclusion

From a Laravel developer’s point of view, for every large system, the debugging time can be high and tedious. But with Laravel new edition- Telescope fills the gap in the development workflow and it helps to develop Laravel applications conveniently and rapidly. Laravel is already extremely popular among Web developers because of the features it offers and now with the addition of the telescope tool in it, they have provided the most complete ecosystem in the industry.

It assists thoroughly to debug both the criteria

Case 1- When we are building the projects
Case 2- When we need additional support for existing websites.

It gives access to a variety of information about the system like queries executed, commands run, views loaded, cache data, exceptions generated and so on. It is a complete debug environment for your applications.

How will customers benefit from Laravel Telescope

The Laravel development team work hard to provide clients a high-performing, scalable and optimized website with codes that work effortlessly without any issues. With the telescope the users no longer have to spend extra hours debugging websites and understand how and what is blocking the code in implementation. They execute faster and hence provide quick resolutions under untimely circumstances, where if something needs to be fetched.

Installation

The documentation is available at Install Laravel Telescope. But In Windows 10, occasionally you may face issues listed as below.

Errors in Windows 10

  • Installation: composer require laravel/telescope
Installation
  • Migrate: $php artisan migrate
    Nothing to migrate.
  • Publish: $php artisan telescope:publish
    Unable to locate publishable resources. Publishing complete.

Our team of Laravel developers has find the solution to outcome from this problem.

Solution:

  1. Copy the project_folder\vendor\laravel\telescope\stubs\TelescopeServiceProvider.php to project_folder\app\Providers\
  2. Add constant TELESCOPE_ENABLED=true to .env file
  3. Then re-run commands at point 2 and 3.

To check that telescope has been installed successfully, start up the application, enter php artisan serve and enter http://127.0.0.1:8000/telescope will open up as below:-

Laravel Telescope

Configuration

The telescope config file is located at config/telescope.php

All the options like path, storage, watchers, etc information are included here. If any particular command or package is supposed to be ignored in the watcher, it has to be mentioned here. If the path needs to be accessed then the telescope is to be updated, and that can also be performed in the config file with a separate option for it.

Understanding the telescope

Let us explore the different sections of telescope

Requests

It gives a detailed information of all the requests coming to application.

Detailed information

Opening any request provides information about the request parameters, headers set, response received as shown here

Headers Response
Request parameters

The authenticated user information is also available on tab.

Authenticated user

Commands

It lists all the Artisan commands run.

Artisan commands

Know more about Laravel PHP framework for web artisans

Clicking on the eye icon lists the arguments, options and events related to the command.

Commands

Schedule

Most of the time, we need to execute a few tasks periodically from the application. For this, we create crons and schedule them to run at a pre-defined time. This section lists all those commands and the output of those scheduled tasks.

Jobs

In case we need to create jobs which need to be executed later after Laravel has completed its implementation then there should be a follow up email a day later. The time consumption can be higher if the user is preparing a zip backup of files. These jobs are put into queues which take care of monitoring and running them according to the order they are received. All these jobs are listed here.

Jobs

Exceptions

All the exceptions thrown in the application can be viewed here. Gives the location and stack trace as well to find the underlying reason behind the exception.

Exceptions

Logs

It lists different types of logs like errors, warnings, info, alerts and so on that are added by the application. This makes it easier to view than to search in the files located in the storage/logs directory.

Logs

Dumps

Several times when debugging the application, on facing any issue, we need to check the variable or object or any data. Using the dump() method and keeping the Dumps page

Open in telescope, the output is visible here.

Dumps

Views

Lists all the views that have been loaded throughout the interaction with the system. Clicking on the eye icon also details the data that has been loaded through the view.

Views

Queries

Queries

One of the most important sections that come in handy anytime is the Queries section. All the queries executed in the system along with their duration are listed here. This helps in knowing all the queries which took longer time to execute and hence needs to be updated to increase the page speed and overall usability of the application.

Models

Models

It lists all the model changes i.e. whenever any created, updated, restored or deleted event occurs.

Events

Events

This section lists all the events of the system along with the listeners information associated with it.

Mail

Lists all the mails that were sent from the system like number of recipients, time of the email sent, subject and also gives a preview of email for better understanding.

Mail

Notifications

Laravel provides an in-built feature to send notifications through different channels like Mail, Slack, Database and SMS. All the mail sent notifications from the system are listed here.

Notifications

Gates

Several times, we need to restrict users to perform any action based on their role. For this purpose, we create gates at app/providers/AuthServiceProvider which takes care of authorization. This section lists the gates and the result of those gates.

Gates

Cache

It shows a list of cache hits, misses, updates, etc. Also, details about the request leading to each cache condition.

Cache

Restricting access to telescope

In the local environment, any user will be able to access the telescope. In production environment, if we want any specific user only to access it, this is possible using the gate function at app/Providers/TelescopeServiceProvider where email address needs to be added here. and multiple emails can be entered.

Multiple emails

Prune

All the entries of telescope data are stored in the telescope_entries table. Now, this table can get accumulated easily. If you want to reduce this then run the prune command.

$schedule->command(‘telescope:prune’)->daily();

This command needs to be added in app\Console\Kernel.php file. It will remove all entries before 24 hours.

If we need to specify the exact hours at which the data should be pruned, it can be done using hours option $schedule->command(‘telescope:prune –hours=12’)->daily()

OR

$schedule->command(‘telescope:prune –hours=12’)->hourly()

Tagging

Sometimes we would want to search for those requests that return 500 error Or

We would want to search for requests related to some specific user. This is also possible using the tagging concept in the ‘telescope’ tool.

Telescope::tag method needs to be added in the register function of TelescopeServiceProvider which will return those requests that are requested.

The other way to add tags On telescope UI is by clicking on the monitoring button, it will allow you to add any tag like Auth:1 and after that, only requests related to the tags will be monitored.

Once done, un-monitoring the button will continue to log requests as it was happening earlier.

Conclusion

Throughout the blog, we saw some of the cutting-edge exceptional features that Telescope provides and by installing it in your application you can definitely have an additional competitive edge and make task processing easier and faster. We would advise you to use a telescope in all your projects in order to leverage the benefits and stay ahead of the peers of the market.

Comments

  • Leave a message...

Related Posts

blog-related-post

Laravel Lazy Collection

July 1, 2020
blog-related-post

Steps to Implement Event Handler in Laravel 5.x Development

November 30, 2018
blog-related-post

Micro framework of Laravel – Lumen

January 9, 2018