Laravel Telescope is a powerful debugging assistant for Laravel applications, providing a beautiful interface to monitor and debug your application’s performance, requests, database queries, and much more. It is an invaluable tool for developers to gain insights into their applications and troubleshoot issues effectively.
Key Features of Laravel Telescope:
- Request Monitoring: Track all incoming HTTP requests to your application, including details about the request and response.
- Database Queries: View the SQL queries executed during a request, including execution time and bindings.
- Exception Logging: Automatically logs exceptions and errors with detailed stack traces for easy debugging.
- Job Monitoring: Monitor queued jobs and their status, including failed jobs.
- Mail Monitoring: See all emails sent from your application, including their contents and recipients.
- Cache Monitoring: Inspect cache operations and their performance.
- Scheduled Tasks: View the status of scheduled tasks executed by Laravel’s task scheduler.
Installation
To get started with Laravel Telescope, follow these steps:
- Install Laravel Telescope: Use Composer to install the package:
1composer require laravel/telescope - Publish Telescope Assets: Publish the Telescope configuration and assets:
1php artisan telescope:install - Run Migrations: Run the migrations to create the necessary tables for Telescope:
1php artisan migrate - Accessing Telescope: You can access the Telescope dashboard at
/telescope
in your browser. By default, Telescope is only enabled for local environments.
Configuring Telescope
You can configure Telescope in the config/telescope.php
file. This file allows you to enable or disable various features, customize the storage for Telescope entries, and more.
Example Configuration
Here’s a basic example of what your config/telescope.php
file might look like:
1 2 3 4 5 6 7 8 9 10 |
return [ 'enabled' => env('TELESCOPE_ENABLED', true), 'driver' => 'database', 'middleware' => ['web', 'auth'], // Other configurations... ]; |
Using Telescope
Once installed and configured, you can start using Telescope to monitor your application.
1. Request Monitoring:
Telescope automatically logs all incoming requests. You can view request details, including:
- Request URL
- Request method (GET, POST, etc.)
- Request headers
- Response status
- Execution time
2. Database Query Monitoring:
You can inspect all SQL queries executed during a request. Telescope shows:
- The SQL query
- Execution time
- Number of bindings
- Database connection used
3. Exception Monitoring:
Telescope logs all exceptions thrown in your application, providing details like:
- Exception message
- Stack trace
- Request data at the time of the exception
4. Job Monitoring:
You can view the status of queued jobs, including:
- Job name
- Status (pending, completed, failed)
- Execution time
- Failed job details
5. Mail Monitoring:
See all emails sent from your application, including:
- Email subject
- Recipients
- Email content (HTML and plain text)
Additional Features
1. Cache Monitoring:
Telescope tracks cache operations, allowing you to see:
- Cache keys
- Cache values
- Cache durations
2. Scheduled Task Monitoring:
View the status of scheduled tasks executed by Laravel’s task scheduler. This includes:
- Task name
- Execution time
- Success or failure status
Authorization
You can control access to Telescope by setting up authorization in your TelescopeServiceProvider
. By default, Telescope is only accessible to users who are authenticated.
Example Authorization Logic
In your App\Providers\TelescopeServiceProvider.php
, you can customize access control:
1 2 3 4 5 6 7 8 9 |
use Laravel\Telescope\Telescope; use Laravel\Telescope\Http\Middleware\Authorize; public function boot() { Telescope::auth(function ($request) { return true; // Allow all users to access Telescope }); } |
Conclusion
Laravel Telescope is an invaluable tool for debugging and monitoring your Laravel applications. Its rich feature set and user-friendly interface make it easy to track performance and identify issues, significantly improving your development workflow.
Additional Considerations
- Performance: Use Telescope in your local environment; it may impact performance in production.
- Security: Make sure to secure the Telescope dashboard by limiting access to authorized users only.
- Storage: Consider the storage driver used by Telescope (database, file, etc.) based on your application’s needs.