This guide shows how to set up and use Laravel Telescope for application monitoring.
📋 Table of Contents
Laravel Telescope is a powerful debugging and monitoring tool for Laravel applications. This guide will show you how to use Telescope to effectively debug, monitor performance, and track errors in your application.
Introduction
Laravel Telescope is an invaluable tool in the process of debugging and monitoring Laravel applications. It facilitates error identification, performance analysis, and system operation control in real-time or from a historical event perspective.
Laravel Telescope is the official debugging tool for the Laravel framework, created by the Laravel team. It enables monitoring of various aspects of application operation, such as SQL queries, HTTP requests, exception handling, queue operations, and many others.
Unlike Laravel Debugbar, which operates in real-time in the browser, Telescope offers a dedicated web interface with operation history, enabling deeper analysis and diagnostics of problems after they occur.
Installation
composer require laravel/telescope --dev
php artisan telescope:install
php artisan migrate
It is recommended to install Telescope as a development dependency (--dev
), as it should not be used in production environments due to performance and security concerns.
Basic Configuration
After installation, the config/telescope.php
file contains all Telescope settings:
<?php
return [
'path' => 'telescope',
'enabled' => env('TELESCOPE_ENABLED', true),
'storage' => [
'database' => [
'connection' => env('DB_CONNECTION', 'mysql'),
'chunk' => 1000,
],
],
'hours' => 24,
'watchers' => [
// ...
],
];
Access Control to Telescope Panel
By default, Telescope is only available in the local environment. To enable access in other environments, modify the gate
method in TelescopeServiceProvider.php
:
protected function gate()
{
Gate::define('viewTelescope', function ($user) {
return in_array($user->email, [
'[email protected]',
'[email protected]'
]);
});
}
Key Features
-
HTTP Request Monitoring
- Records all incoming HTTP requests with details:
- URL, HTTP Method, Parameters, Headers, Response Code, Execution Time
- Records all incoming HTTP requests with details:
-
Database Query Monitoring
- Logs all SQL queries:
- Full SQL Query, Parameters, Execution Time
$users = DB::table('users')->where('active', true)->orderBy('created_at', 'desc')->get();
- Logs all SQL queries:
-
Exception Monitoring
- Automatically saves all exceptions with type, trace, location, context
-
Cache Operation Monitoring
- Tracks get/set/forget operations
Cache::put('user_profile', $userProfile, 3600); $profile = Cache::get('user_profile');
-
Queue Job Monitoring
- Records queued and executed queue jobs
ProcessPodcast::dispatch($podcast)->onQueue('podcasts');
-
Log Monitoring
- All log entries
Log::info('User logged in', ['user_id' => $user->id]);
-
Notification Monitoring
- Tracks notifications with type, channel, status
-
Event Monitoring
- Tracks events, payload, and listeners
event(new UserRegistered($user));
-
Eloquent Model Monitoring
- Hydration, serialization, collection operations
-
Artisan Command Monitoring
- Records all commands, time, options
Security
Conclusion
Laravel Telescope is an essential tool for every Laravel developer, offering:
- Comprehensive application monitoring
- Detailed request and query tracking
- Efficient error debugging
- Docker integration
- Advanced security features
Follow me on LinkedIn to receive more tips about Laravel and DevOps!
Would you like to learn more about debugging and monitoring Laravel applications? Let me know in the comments below!