{"id":411,"date":"2025-08-27T21:04:56","date_gmt":"2025-08-27T21:04:56","guid":{"rendered":"https:\/\/1v0.net\/blog\/?p=411"},"modified":"2025-08-27T21:04:58","modified_gmt":"2025-08-27T21:04:58","slug":"using-laravel-telescope-to-debug-performance-issues","status":"publish","type":"post","link":"https:\/\/1v0.net\/blog\/using-laravel-telescope-to-debug-performance-issues\/","title":{"rendered":"Using Laravel Telescope to Debug Performance Issues"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><strong>Using Laravel Telescope to Debug Performance Issues<\/strong><\/h2>\n\n\n\n<p>When your Laravel app slows down under traffic, it can be difficult to know whether the issue is database queries, cache misses, slow jobs, or external APIs. <strong>Laravel Telescope<\/strong> is a powerful debugging assistant that gives you full visibility into what your app is doing in real time. In this guide, we\u2019ll install Telescope, explore its dashboard, and learn how to use it to identify and fix performance bottlenecks.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><strong>1 &#8211; Install Telescope<\/strong><\/h2>\n\n\n\n<p>Telescope is a Laravel package maintained by the core team. It\u2019s usually installed as a development dependency, but can also be deployed in production with proper authentication.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">composer require laravel\/telescope --dev\nphp artisan telescope:install\nphp artisan migrate<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This installs Telescope, publishes its assets, and sets up the necessary database tables to store logs and metrics.<\/p>\n\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><strong>2 &#8211; Protecting the Telescope Dashboard<\/strong><\/h2>\n\n\n\n<p>The dashboard is available at <code>\/telescope<\/code>. You should restrict access to only admins or local environments for security.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/\/ app\/Providers\/TelescopeServiceProvider.php<\/span>\n<span class=\"hljs-keyword\">protected<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">gate<\/span><span class=\"hljs-params\">()<\/span>\n<\/span>{\n    Gate::define(<span class=\"hljs-string\">'viewTelescope'<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-params\">($user)<\/span> <\/span>{\n        <span class=\"hljs-keyword\">return<\/span> in_array($user-&gt;email, &#91;\n            <span class=\"hljs-string\">'admin@example.com'<\/span>,\n        ]);\n    });\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This gate ensures only whitelisted users can access Telescope in production. In local environments, it\u2019s usually open by default.<\/p>\n\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><strong>3 &#8211; Monitoring Queries<\/strong><\/h2>\n\n\n\n<p>Telescope shows every query executed in your app, with bindings and execution times. This helps spot <strong>N+1 problems<\/strong> and missing indexes quickly.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/\/ Example of an N+1 problem<\/span>\n$users = User::all();\n\n<span class=\"hljs-keyword\">foreach<\/span> ($users <span class=\"hljs-keyword\">as<\/span> $user) {\n    <span class=\"hljs-keyword\">echo<\/span> $user-&gt;posts-&gt;count(); <span class=\"hljs-comment\">\/\/ triggers extra query for each user<\/span>\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Telescope will display hundreds of queries in this case, showing the N+1 issue. The fix is eager loading:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/\/ Optimized with eager loading<\/span>\n$users = User::with(<span class=\"hljs-string\">'posts'<\/span>)-&gt;get();\n\n<span class=\"hljs-keyword\">foreach<\/span> ($users <span class=\"hljs-keyword\">as<\/span> $user) {\n    <span class=\"hljs-keyword\">echo<\/span> $user-&gt;posts-&gt;count(); <span class=\"hljs-comment\">\/\/ no extra queries<\/span>\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Now Telescope will show just two queries: one for users, one for posts. For more on this technique, see <a href=\"\/blog\/eager-loading-vs-lazy-loading-in-laravel-best-practices\">Eager Loading vs Lazy Loading in Laravel: Best Practices<\/a>.<\/p>\n\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><strong>4 &#8211; Tracking Requests &amp; Exceptions<\/strong><\/h2>\n\n\n\n<p>Telescope records every incoming request and any exceptions thrown. This is extremely useful for debugging performance-related errors.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/\/ Example: log request info in Telescope<\/span>\nRoute::get(<span class=\"hljs-string\">'\/profile'<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-params\">()<\/span> <\/span>{\n    <span class=\"hljs-keyword\">return<\/span> view(<span class=\"hljs-string\">'profile'<\/span>);\n});<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>When visiting <code>\/profile<\/code>, Telescope shows request duration, middleware stack, and queries executed. Exceptions appear in a separate tab, making it easy to trace issues.<\/p>\n\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><strong>5 &#8211; Monitoring Queues &amp; Jobs<\/strong><\/h2>\n\n\n\n<p>Telescope integrates with Laravel\u2019s queue system. It shows processed jobs, pending jobs, and failures in real time. This complements <a href=\"\/blog\/how-to-use-laravel-queues-for-faster-performance\">queues<\/a> and <a href=\"\/blog\/how-to-use-laravel-horizon-for-queue-monitoring\">Horizon<\/a>, giving you both deep debugging and production monitoring tools.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/\/ Dispatch a queued job<\/span>\nSendWelcomeEmail::dispatch($user);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>After dispatching a job, check Telescope\u2019s <strong>Jobs<\/strong> tab. You\u2019ll see job payload, execution time, and retry history\u2014perfect for debugging job performance.<\/p>\n\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><strong>6 &#8211; Insights into Cache &amp; Redis<\/strong><\/h2>\n\n\n\n<p>Telescope logs cache hits and misses. This is critical when evaluating <a href=\"\/blog\/caching-strategies-in-laravel-redis-vs-database-vs-file\">caching strategies<\/a> for high-traffic apps.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/\/ Example: cached query<\/span>\nCache::remember(<span class=\"hljs-string\">'users.active'<\/span>, <span class=\"hljs-number\">60<\/span>, <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-params\">()<\/span> <\/span>{\n    <span class=\"hljs-keyword\">return<\/span> User::active()-&gt;get();\n});<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Telescope shows whether the result came from cache or DB. This makes it easier to validate that caching is working and saving resources.<\/p>\n\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\"><strong>7 &#8211; Profiling Performance<\/strong><\/h2>\n\n\n\n<p>Telescope records timeline data for every request: middleware duration, query time, job dispatch delays, etc. This is invaluable for pinpointing slow points in your app\u2019s lifecycle.<\/p>\n\n\n\n<p>Combine Telescope insights with <a href=\"\/blog\/optimizing-laravel-for-high-concurrency-with-octane\">Octane<\/a> to spot memory leaks and performance issues in persistent worker setups.<\/p>\n\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p><strong>Laravel Telescope<\/strong> provides real-time visibility into queries, requests, jobs, cache, and exceptions. It\u2019s a must-have tool for debugging performance issues in development and can be secured for production use. With Telescope, you can spot bottlenecks like N+1 queries, missing indexes, or slow jobs before they impact your users.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n\n<h2 class=\"wp-block-heading\">What\u2019s Next<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"\/blog\/10-proven-ways-to-optimize-laravel-for-high-traffic\">10 Proven Ways to Optimize Laravel for High Traffic<\/a> \u2014 overview of caching, queues, and scaling.<\/li>\n<li><a href=\"\/blog\/how-to-use-laravel-queues-for-faster-performance\">How to Use Laravel Queues for Faster Performance<\/a> \u2014 improve response times by moving tasks into queues.<\/li>\n<li><a href=\"\/blog\/caching-strategies-in-laravel-redis-vs-database-vs-file\">Caching Strategies in Laravel: Redis vs Database vs File<\/a> \u2014 ensure your cache strategy supports high performance.<\/li>\n<\/ul>\n\n","protected":false},"excerpt":{"rendered":"<p>Using Laravel Telescope to Debug Performance Issues When your Laravel app slows down under traffic, it can be difficult to know whether the issue is database queries, cache misses, slow jobs, or external APIs. Laravel Telescope is a powerful debugging assistant that gives you full visibility into what your app is doing in real time. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":415,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[72,44,73],"class_list":["post-411","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","tag-debugging","tag-performance","tag-telescope"],"_links":{"self":[{"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/posts\/411","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/comments?post=411"}],"version-history":[{"count":1,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/posts\/411\/revisions"}],"predecessor-version":[{"id":414,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/posts\/411\/revisions\/414"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/media\/415"}],"wp:attachment":[{"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/media?parent=411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/categories?post=411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/1v0.net\/blog\/wp-json\/wp\/v2\/tags?post=411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}