laravel/telescope
Laravel Telescope is a debug assistant for Laravel that gives deep visibility into app activity: incoming requests, exceptions, logs, database queries, queued jobs, mail, notifications, cache events, scheduled tasks, dumps, and more—ideal for local development.
Install Telescope via Composer:
composer require laravel/telescope --dev
Publish Telescope’s assets and configuration:
php artisan telescope:install
Run the migration to create the necessary database tables:
php artisan migrate
Start Telescope in your local environment by adding it to routes/web.php:
Route::middleware(['web', 'telescope.screenshots', 'telescope'])
->group(function () {
\Laravel\Telescope\Telescope::routes();
});
Access Telescope at /telescope (protected by auth:sanctum by default). For quick debugging, use the telescope:clear command to reset entries.
First Use Case: Debug a failing request by inspecting its HTTP details, exceptions, and database queries in Telescope’s dashboard.
Request Debugging
api, admin) or time ranges for targeted debugging.public function handle($request, Closure $next) {
$request->telescopeData['tags'] = ['api', 'v1'];
return $next($request);
}
Exception Tracking
Database Query Analysis
DB::enableQueryLog() pattern to manually log queries:
DB::enableQueryLog();
// ... code ...
Telescope::logQuery(DB::getQueryLog());
Job Monitoring
default, high).Custom Data Logging
Telescope::log():
Telescope::log('Custom Event', [
'user_id' => auth()->id(),
'action' => 'purchase',
]);
TelescopeMiddleware to automatically tag requests:
public function handle($request, Closure $next) {
$request->telescopeData['tags'] = ['authenticated'];
return $next($request);
}
public function boot() {
Telescope::make()->extend(function ($telescope) {
$telescope->watch(\App\Services\StripeService::class);
});
}
TELESCOPE_ENABLED=false in .env.Performance Overhead
'limit' => 1000, // config/telescope.php
telescope:prune to clean old entries:
php artisan telescope:prune --hours=24
Database Bloat
telescope_entries table grows rapidly. Monitor size and prune aggressively in staging:
php artisan telescope:prune --hours=1
Middleware Conflicts
Route::middleware(['web', 'telescope.screenshots'])->group(function () {
// Exclude sensitive routes
});
Asset Compilation
npm run dev
php artisan telescope:clear && npm run dev
TELESCOPE_ENABLED=true and the telescope middleware is registered.DB::enableQueryLog() for raw SQL inspection. Telescope formats queries but may miss context.Telescope::log() with serialize: false to avoid bloating entries:
Telescope::log('Job Payload', ['data' => $job->payload], serialize: false);
Custom Watchers
use Laravel\Telescope\Contracts\Watcher;
class CacheWatcher implements Watcher {
public function report($payload) {
return [
'message' => 'Cache miss',
'key' => $payload['key'],
];
}
}
AppServiceProvider@boot():
Telescope::make()->extend(CacheWatcher::class);
Filtering Entries
AppServiceProvider:
use Laravel\Telescope\Telescope;
Telescope::filter(function ($query) {
return $query->where('tags', 'like', '%api%');
});
Localization
php artisan vendor:publish --tag=telescope-lang
resources/lang/en/telescope.php.Security
config/telescope.php:
'middleware' => ['auth:sanctum', 'verified'],
'local' => [
'middleware' => ['throttle:100'],
],
How can I help you explore Laravel packages today?