0 Shares 2455 Views

Laravel Telescope for Easy Developing

Laravel Telescope for Easy Developing

Hello everyone 👋

Today we will talk about a package that makes things a lot easier when developing. Our package is called Telescope. Briefly, a package that gives us all the details about where it starts and how it ends for Requests, Errors, Records, Database queries, the status of jobs in the queue, Mail, Notification, Cache, and Scheduled jobs on our application. It will be very useful when developing!

Let’s start …

laravel telescop

Setup

We have a simple installation way through Composer. You can access all Documentation on https://laravel.com/docs/8.x/telescope.

<code>composer require laravel/telescope</code>

and then installation

<code>

php artisan telescope:install

php artisan migrate

</code>

We continue with the steps here in our database

<code>

2018_08_08_100000_create_telescope_entries_table

</code>

Database tables of the telescope will be created over the migration file.

Settings

After completing its installation on Laravel, a “config / telescope.php” file will be created. Here, the options we can turn on or turn off the telescope are explained in detail.

<code>

‘enabled’ => env(‘TELESCOPE_ENABLED’, true),

</code>

It is possible to turn it off completely by setting false.

Clearing data

We can ensure that the records in our database are deleted at intervals we determined concerning the increase and occupation of space in a long time. For this, we will make use of Scheduled tasks, a feature of Laravel. We will do it this way.

<code>

#/app/Console/Kernel.php/**

* Define the application’s command schedule.

*

* @param \Illuminate\Console\Scheduling\Schedule $schedule

* @return void

*/

protected function schedule(Schedule $schedule)

{

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

}

 

</code>

Here we told our application that it needs to clear data daily. The command “telescope: prune” is set to delete data from the past 24 hours by default. If we want to change this, we need to add an additional parameter. We can do this as follows.

<code>

$schedule->command(‘telescope:prune –hours=48’)->daily();

</code>

Here we have said that the last 48 hours of the recording should be preserved and the rest should be deleted. You can get detailed information on https://laravel.com/docs/8.x/scheduling.

Night Mode

<code>

# app/Providers/TelescopeServiceProvideruse Laravel\Telescope\IncomingEntry;

use Laravel\Telescope\Telescope;

/**

* Register any application services.

*

* @return void

*/

public function register()

{ /** Telescope night mode by deleting the comment line

* can be passed to the design.

**/

Telescope::night();

….

</code>

Authorization

If we want to adjust who can access the data on the control panel, which we will talk about shortly.

<code>

#/app/Providers/TelescopeServiceProvider/**

* 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, [

“tolga.karabulut@medianova.com”

]);

});

}

</code>

We can do it. Specify here, except users whose mail addresses are logged in will not be able to access the control panel. Here I will explain later on how to access API servers with JWT.

Filtering Requests

Here we can edit the contents to be watched between our local and production servers. By default, it looks like this.

<code>

# app/Providers/TelescopeServiceProvideruse Laravel\Telescope\IncomingEntry;

use Laravel\Telescope\Telescope;

/**

* Register any application services.

*

* @return void

*/

public function register()

{

// Telescope::night();

 

$this->hideSensitiveRequestDetails();

 

Telescope::filter(function (IncomingEntry $entry) {

/**

* If the application is in local state, no filtering is applied.

*/

if ($this->app->environment(‘local’)) {

return true;

}

/**

* If not

* Wrong Requests

* Planned Actions, Not Completed Jobs

* etc. situations are not displayed on the telescope.

*/

return $entry->isReportableException() ||

$entry->isFailedRequest() ||

$entry->isFailedJob() ||

$entry->isScheduledTask() ||

$entry->hasMonitoredTag();

});

}

</code>

Tags

By tags the incoming requests on the telescope with a tag system, we can find it more comfortably in searches later. We follow a path for this.

<code>

# app/Providers/TelescopeServiceProvideruse Laravel\Telescope\IncomingEntry;

use Laravel\Telescope\Telescope;

/**

* Register any application services.

*

* @return void

*/

public function register()

{

/**

* If the type of the request is “Request”, we group it according to the 

* status code of the request.

*/

Telescope::tag(function (IncomingEntry $entry) {

return $entry->type === ‘request’

? [‘status:’.$entry->content[‘response_status’]]

: [];

}); …

</code>

Here we see all the requests right now. We have tagged requests. By typing “status: 404” in the search bar, we can filter the “404 – Not Found” ones.

Watchers

He learned how to manage the unwanted situations of watched content in the filtering part. If we want to turn the tracking off or on, the audience comes into play. We can set it as follows.

<code>

# config/telescope.php

‘watchers’ => [

Watchers\CacheWatcher::class => true,

Watchers\CommandWatcher::class => false,

Watchers\ViewWatcher::class => true, 

],

</code>

You can make additional settings for some viewers. For example;

<code>

‘watchers’ => [

…. Watchers\QueryWatcher::class => [

‘enabled’ => true,

‘slow’ => 100,

], … Watchers\CommandWatcher::class => [

‘enabled’ => env(‘TELESCOPE_COMMAND_WATCHER’, true),

‘ignore’ => [‘key:generate’],

],

… Watchers\ModelWatcher::class => [

‘enabled’ => env(‘TELESCOPE_MODEL_WATCHER’, true),

‘events’ => [‘eloquent.created*’, ‘eloquent.updated*’],

],

…],/**

* Query Watcher

* Here, if a SQL query takes longer than 100ms, it will be shown to you as 

* a log.

*

*

* CommandWatcher

* We say that [“key: generate”] command should not be followed

* while following the commands we run through the terminal.

*

*

* ModelWatcher

*

* Following only “Create” – “Updated” processes on the model

* we are telling that it should not be.

**/

</code>

You can examine all other details by examining the file and through the document. You can access the sample project on Github.

We have come to the end of another subject. You can send all your questions by writing under the topic or through my social media accounts.

Good Coding for Everyone!

You may be interested

The Ultimate CDN (Content Delivery Network) Guide
CDN
5794 views
CDN
5794 views

The Ultimate CDN (Content Delivery Network) Guide

Nadia Benslimane - August 3, 2020

The Ultimate CDN Guide- Everything About Content Delivery Network You probably know what CDN (Content Delivery Network) stands for. You may also be aware of its full definition,…

The Essential CDN Glossary
CDN
9942 views
CDN
9942 views

The Essential CDN Glossary

Nadia Benslimane - November 21, 2019

Why Have We Decided To Create a CDN Glossary? Whether you are new to the world of CDN, or have been involved in it for years, there…

The Benefits of CDN for the Gaming Industry
CDN
1244 views
CDN
1244 views

The Benefits of CDN for the Gaming Industry

alikayikci - December 3, 2021

The Benefits of CDN for the Gaming Industry The gaming industry has witnessed a phenomenal growth in the last few years. The global nine gaming market only…

HTTP Live Streaming
CDN
577 views
CDN
577 views

HTTP Live Streaming

medianova - November 1, 2021

Introduction To HTTP Live Streaming What Is HTTP Live Streaming (HLS)? HLS (HTTP live streaming) is one of the most widely used video streaming protocols. Although live…

All You Need to Know About Round-Trip Time
CDN
647 views
CDN
647 views

All You Need to Know About Round-Trip Time

Gizay Yalçın - October 20, 2021

What exactly is RTT?  Round-trip time (RTT) is a networking metric that measures in milliseconds the time it takes for a data packet to be sent and…

Most from this category

The Ultimate CDN (Content Delivery Network) Guide
CDN
5794 views
5794 views

The Ultimate CDN (Content Delivery Network) Guide

Nadia Benslimane - August 3, 2020
The Essential CDN Glossary
CDN
9942 views
9942 views

The Essential CDN Glossary

Nadia Benslimane - November 21, 2019
SD-WAN in CDNs
CDN
416 views
416 views

SD-WAN in CDNs

Gizay Yalçın - October 20, 2021
Health Check Backup Origin
CDN
398 views
398 views

Health Check Backup Origin

Nilgün Ünsal - October 17, 2021
DDoS Attack Trends in 2021
CDN
692 views
692 views

DDoS Attack Trends in 2021

Elif Ak - October 17, 2021
Web Application Firewall
Uncategorized
170 views
170 views

Web Application Firewall

Aykut Teker - September 30, 2021