Lightweight Laravel Request Inspector with Tagged Cache | Mohamed Said        [  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MH.png)   Mohamed Said Laravel Backend Engineer  ](https://msaied.com) [ Home ](https://msaied.com) [ Projects ](https://msaied.com/projects) [ Articles  ](https://msaied.com/articles) [ Certificates ](https://msaied.com/certificates) [ Contact ](https://msaied.com#contact-section) 

       [  ](https://github.com/EG-Mohamed)       

 [ Home ](https://msaied.com) [ Projects ](https://msaied.com/projects) [ Articles ](https://msaied.com/articles) [ Certificates ](https://msaied.com/certificates) [ Contact ](https://msaied.com#contact-section) 

  [ home ](https://msaied.com)    [ articles ](https://msaied.com/articles)    Laravel Telescope Alternatives: Building a Lightweight Request Inspector with Tagged Cache        On this page       1. [  Why Not Just Use Telescope in Production? ](#why-not-just-use-telescope-in-production)
2. [  The Core Idea: Tagged Cache as a Ring Buffer ](#the-core-idea-tagged-cache-as-a-ring-buffer)
3. [  Storing Query Counts Without a Full Query Log ](#storing-query-counts-without-a-full-query-log)
4. [  Surfacing Data in a Filament Panel ](#surfacing-data-in-a-filament-panel)
5. [  Enabling Only When Needed ](#enabling-only-when-needed)
6. [  Takeaways ](#takeaways)

  ![Laravel Telescope Alternatives: Building a Lightweight Request Inspector with Tagged Cache](https://cdn.msaied.com/287/9b41ffff50d97af1f781c154d468bfca.png)

  #laravel   #filament   #performance   #debugging   #middleware  

 Laravel Telescope Alternatives: Building a Lightweight Request Inspector with Tagged Cache 
============================================================================================

     25 Jun 2026      4 min read    ![Mohamed Said](https://cdn.msaied.com/01M22N44A70A5MC2S599JP0MPH.webp)  Mohamed Said  

       Table of contents

1. [  01   Why Not Just Use Telescope in Production?  ](#why-not-just-use-telescope-in-production)
2. [  02   The Core Idea: Tagged Cache as a Ring Buffer  ](#the-core-idea-tagged-cache-as-a-ring-buffer)
3. [  03   Storing Query Counts Without a Full Query Log  ](#storing-query-counts-without-a-full-query-log)
4. [  04   Surfacing Data in a Filament Panel  ](#surfacing-data-in-a-filament-panel)
5. [  05   Enabling Only When Needed  ](#enabling-only-when-needed)
6. [  06   Takeaways  ](#takeaways)

 Why Not Just Use Telescope in Production?
-----------------------------------------

Laravel Telescope is excellent during development, but its write-on-every-request model — storing queries, jobs, logs, and HTTP payloads to a dedicated database table — creates measurable overhead and a growing storage footprint. Most teams disable it in production entirely, leaving a blind spot for intermittent issues that only appear under real traffic.

The goal here is a *targeted* inspector: capture only what you opt into, store it ephemerally in Redis via tagged cache, and surface it through a locked-down Filament panel. No extra database tables, no always-on overhead.

The Core Idea: Tagged Cache as a Ring Buffer
--------------------------------------------

Redis supports tagging via Laravel's `Cache::tags()`. We can write request snapshots under a shared tag and expire them automatically, giving us a rolling window of recent traffic without permanent storage.

```php
// app/Http/Middleware/InspectRequest.php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;

class InspectRequest
{
    public function handle(Request $request, Closure $next): mixed
    {
        $response = $next($request);

        if (! config('inspector.enabled')) {
            return $response;
        }

        $key = 'req:' . Str::uuid();

        Cache::tags(['inspector'])->put($key, [
            'method' => $request->method(),
            'path' => $request->path(),
            'status' => $response->getStatusCode(),
            'duration_ms' => (int) ((microtime(true) - LARAVEL_START) * 1000),
            'memory_kb' => (int) (memory_get_peak_usage(true) / 1024),
            'ip' => $request->ip(),
            'at' => now()->toIso8601String(),
        ], now()->addMinutes(30));

        return $response;
    }
}

```

Register it selectively — not globally — using a route group or a specific middleware alias so you control which routes are traced.

Storing Query Counts Without a Full Query Log
---------------------------------------------

Rather than logging every SQL statement (Telescope's approach), count them cheaply using the DB `listen` callback scoped to the request lifecycle:

```php
// Inside InspectRequest::handle, before $next($request)

$queryCount = 0;
\DB::listen(static function () use (&$queryCount) {
    $queryCount++;
});

$response = $next($request);

// Then include $queryCount in the Cache::tags()->put() payload above.

```

This adds negligible overhead compared to capturing full bindings and execution times for every query.

Surfacing Data in a Filament Panel
----------------------------------

Create a read-only Filament resource backed not by Eloquent but by a custom `getTableQuery` override that reads from the tagged cache.

```php
// app/Filament/Resources/RequestSnapshotResource.php

public static function table(Table $table): Table
{
    return $table
        ->columns([
            TextColumn::make('method')->badge(),
            TextColumn::make('path'),
            TextColumn::make('status')->badge()
                ->color(fn ($state) => $state >= 500 ? 'danger' : ($state >= 400 ? 'warning' : 'success')),
            TextColumn::make('duration_ms')->suffix(' ms')->sortable(),
            TextColumn::make('query_count')->label('Queries'),
            TextColumn::make('at')->since(),
        ])
        ->paginated([25, 50]);
}

public static function getEloquentQuery(): Builder
{
    // Filament expects a Builder; wrap cache reads in a collection-backed fake.
    // Use a custom ListRecords page that overrides getTableRecords() instead.
    throw new \LogicException('Use custom list page.');
}

```

The cleaner approach is to override `getTableRecords()` in a custom `ListRequestSnapshots` page:

```php
protected function getTableRecords(): Collection
{
    $keys = Redis::connection()->keys('*inspector*req:*');

    return collect($keys)
        ->map(fn ($key) => Cache::tags(['inspector'])->get(
            Str::after($key, config('cache.prefix') . 'inspector|')
        ))
        ->filter()
        ->sortByDesc('at')
        ->values();
}

```

Lock the panel behind a gate or a dedicated guard so it is never publicly accessible.

Enabling Only When Needed
-------------------------

Add a runtime toggle via an artisan command that flips a cache flag:

```bash
php artisan inspector:on  # sets inspector.enabled in cache for 1 hour
php artisan inspector:off

```

The middleware reads `Cache::get('inspector.enabled', false)` so there is zero overhead when the inspector is off.

Takeaways
---------

- **Tagged cache as ephemeral storage** gives you a self-expiring ring buffer with no schema migrations.
- **Opt-in middleware** keeps production overhead at zero when the inspector is disabled.
- **Query counting, not logging**, captures the signal you actually need (N+1 detection) without the storage cost.
- **A Filament panel** gives you a polished UI without building a custom frontend.
- **Runtime toggle via artisan** lets you enable tracing surgically during an incident and disable it immediately after.

 Found this useful?

          [  ](https://twitter.com/intent/tweet?url=https%3A%2F%2Fmsaied.com%2Farticles%2Flaravel-telescope-alternatives-building-a-lightweight-request-inspector-with-tagged-cache&text=Laravel+Telescope+Alternatives%3A+Building+a+Lightweight+Request+Inspector+with+Tagged+Cache) [  ](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fmsaied.com%2Farticles%2Flaravel-telescope-alternatives-building-a-lightweight-request-inspector-with-tagged-cache) 

 Frequently Asked Questions 
----------------------------

  3 questions  

     Q01  Does tagged cache work with all Laravel cache drivers?        No. Cache tags require a driver that supports them — Redis and Memcached. The file and database drivers do not support tagging, so this approach requires Redis in production. 

      Q02  How do I prevent the inspector from capturing sensitive request payloads?        Simply omit request body and headers from the cache payload. The middleware shown here stores only method, path, status, timing, and memory — no user data. Add fields deliberately and scrub anything sensitive before writing to cache. 

      Q03  Can I extend this to capture slow queries specifically?        Yes. Replace the simple counter with a DB::listen callback that appends queries exceeding a threshold (e.g. 100 ms) to a separate array, then include that array in the cache payload. This keeps storage bounded while surfacing the queries that actually matter. 

  Continue reading

 More Articles 
---------------

 [ View all    ](https://msaied.com/articles) 

 [ ![Laravel Live Denmark 2026 Talks Are Now on YouTube](https://cdn.msaied.com/694/ef171df318406f98f554df18e58af625.png) Laravel PHP Conference 

### Laravel Live Denmark 2026 Talks Are Now on YouTube

All 17 talks from Laravel Live Denmark 2026 are now on YouTube. The playlist covers PHP generics, Inertia, Nat...

  ![Mohamed Said](https://cdn.msaied.com/01M22N44A70A5MC2S599JP0MPH.webp)  Mohamed Said 

 22 Sep 2026     3 min read  

  Read    

 ](https://msaied.com/articles/laravel-live-denmark-2026-talks-are-now-on-youtube) [ ![Live Stream: Building a Social Network in PHP in 48 Hours](https://cdn.msaied.com/692/e20cfd66bbb0473d2084f86b7f5e4dcc.png) PHP Live Stream Nuno Maduro 

### Live Stream: Building a Social Network in PHP in 48 Hours

Nuno Maduro, Brent Roose, and Matthieu Napoli will build a full social network in PHP live from the JetBrains...

  ![Mohamed Said](https://cdn.msaied.com/01M22N44A70A5MC2S599JP0MPH.webp)  Mohamed Said 

 22 Sep 2026     2 min read  

  Read    

 ](https://msaied.com/articles/live-stream-building-a-social-network-in-php-in-48-hours) [ ![Livewire v4.4.6 Released: Bug Fixes, Test Improvements, and Alpine v3.17.4](https://cdn.msaied.com/689/454c52282f3ef5d585905e5952ca969c.png) Livewire Laravel Alpine.js 

### Livewire v4.4.6 Released: Bug Fixes, Test Improvements, and Alpine v3.17.4

Livewire v4.4.6 ships with 18 changes including validation performance improvements, better test assertions, k...

  ![Mohamed Said](https://cdn.msaied.com/01M22N44A70A5MC2S599JP0MPH.webp)  Mohamed Said 

 21 Sep 2026     3 min read  

  Read    

 ](https://msaied.com/articles/livewire-v446-released-bug-fixes-test-improvements-and-alpine-v3174) 

   [  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MH.png)   Mohamed Said Laravel Backend Engineer  ](https://msaied.com)Senior Backend Engineer specializing in Laravel, scalable SaaS platforms, APIs, and cloud infrastructure. I build secure, high-performance web applications that help businesses grow.

Explore

- [Home](https://msaied.com)
- [Projects](https://msaied.com/projects)
- [Articles](https://msaied.com/articles)
- [Certificates](https://msaied.com/certificates)
- [Contact](https://msaied.com#contact-section)

Connect

- [   hello@msaied.com ](mailto:hello@msaied.com)
- [   +20 109 461 9204 ](tel:+201094619204)

© 2026 Mohamed Said. All rights reserved.

 [  ](https://github.com/EG-Mohamed) [  ](https://www.linkedin.com/in/msaiedm/) [  ](https://wa.me/201094619204) [  ](mailto:hello@msaied.com) [  ](https://drive.google.com/file/u/0/d/1MF20IPRJyzfy32mhEutjL5EpSls0w2Q8/view)
