Performing monitoring and debugging techniques is very important when developing an application, especially a website. By applying these two techniques, we can improve running queries, fix performance issues, and quickly and easily resolve errors that occur. In this article, we will discuss one of the official tools from Laravel, namely Laravel Telescope, to address these issues.
What is Laravel Telescope?
Laravel Telescope is a debug assistant designed for monitoring and debugging the Laravel framework. This tool provides insights into incoming HTTP requests to the application, including exceptions, log entries, database queries, and more.
Advantages of Using Laravel Telescope
- Real-Time Monitoring - monitor activity on the application in real time.
- User-Friendly Interface - an intuitive dashboard interface for all users.
- Logging - records all application activities in detail.
- Performance Analysis - analyzes query performance and response times.
- Easy Integration - seamlessly integrates with existing Laravel projects.
Key Features of Laravel Telescope
- HTTP Request Monitoring
Telescope records all HTTP requests that enter our application, including:
- URL and HTTP method.
- Response status and time.
- Request headers and parameters.
- Session data.
- Database Query Analysis
With this feature, we can optimize database performance, such as:
- Slow Query - detect slow queries.
- Query Count - count the number of queries per request.
- N+! Problem - detect queries that are indicated as N+1.
- Query Execution Time - measure query execution time.
- Job Monitoring
For applications that use a queue system such as:
- Job payload.
- Job Execution time.
- Retry attempts.
- Error messages for failed jobs
- Mail Monitoring
Tracking all emails sent through the application:
- Attachment details.
- Delivery status
- Cache operation
Cache monitoring.
Preparation
Before installing Laravel Telescope, make sure you meet the following requirements:
- PHP >= 7.2
- Laravel >= 5.7
- Database Config (MySQL, PostgreeSQL, etc.)
Installing Laravel Telescope
Open the terminal, paste the bash script below into your respective terminals.
composer require laravel/telescope
After that, install Laravel Telescope into our application with the command below.
php artisan telescope:install
Run the database migration
php artisan migrate
Open the .env
file and add the following configuration.
TELESCOPE_ENABLED=true
After that, open your browser and access the URL http://127.0.0.1:8000/telescope
.
Custom Laravel Telescope Configuration
We may need to configure Laravel Telescope after installation, although this is optional
. You need to open the config/telescope.php file first if you want to configure it.
- Storage Configuration
If you are using a database other than MySQL
, you need to configure it as follows.
‘storage’ => [
‘database’ => [
‘connection’ => env(‘DB_CONNECTION’, ‘pgsql’), //assuming we use PostgreeSQL
'chunk' => 1000,
],
],
or we can also add the following code to the .env
file.
DB_CONNECTION=pgsql
- Custom Path
The default URL for Laravel Telescope is /telescope
, which can be changed with the configuration below.
‘path’ => env(‘TELESCOPE_PATH’, ‘monitoring’),
Now you can access Laravel Telescope using the URL /monitoring
.
Or by adding the following code to the .env
file.
TELESCOPE_PATH=monitoring
- Queue Configuration
If the application has already installed Redis for queue, we need to configure Laravel Telescope as follows.
‘queue’ => [
‘connection’ => env(‘TELESCOPE_QUEUE_CONNECTION’, ‘redis’),
‘queue’ => env(‘TELESCOPE_QUEUE’, ‘default’),
‘delay’ => env(‘TELESCOPE_QUEUE_DELAY’, 10),
],
Or by adding code to the .env
file like this.
TELESCOPE_QUEUE_CONNECTION=redis
TELESCOPE_QUEUE=default
TELESCOPE_QUEUE_DELAY=10
FAQ
- Q: Is Laravel Telescope free?
A: Yes, Laravel Telescope is free and open-source to use.
- Q: Can Laravel Telescope be used in a production environment?
A: It is possible, but not recommended due to performance impact and security issues.
- Q: Is Laravel Telescope compatible with all versions of Laravel?
A: Laravel Telescope requires at least Laravel version 5.7 or higher.
- Q: How do I back up Laravel Telescope data?
A: Data in Laravel Telescope is stored in a database, so it will be backed up during regular database backups.
Conclusion
Laravel Telescope is a very powerful tool for monitoring, debugging, and optimizing Laravel applications. With its comprehensive features, Telescope helps developers identify and resolve issues quickly.
Proper use of Laravel Telescope significantly improves application quality, reduces bugs in production, and provides insights into how the application performs in real-world scenarios.
Thank you.