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/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  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 Queues: Job Middleware for Idempotency, Rate Limiting, and Graceful Failure](https://cdn.msaied.com/288/46c6bf48663538a47ca37b0655c41674.png) laravel queues job-middleware 

### Laravel Queues: Job Middleware for Idempotency, Rate Limiting, and Graceful Failure

Beyond basic dispatching, Laravel job middleware lets you enforce idempotency, apply fine-grained rate limits,...

  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said 

 25 Jun 2026     1 min read  

  Read    

 ](https://msaied.com/articles/laravel-queues-job-middleware-for-idempotency-rate-limiting-and-graceful-failure) [ ![Laravel Telescope Alternatives: Building a Lightweight Request Inspector with Middleware](https://cdn.msaied.com/286/d19897a1c3c3f05e29186428776cf9e1.png) laravel middleware filament 

### Laravel Telescope Alternatives: Building a Lightweight Request Inspector with Middleware

Telescope is indispensable in development, but its overhead makes it unsuitable for production debugging. Lear...

  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said 

 25 Jun 2026     1 min read  

  Read    

 ](https://msaied.com/articles/laravel-telescope-alternatives-building-a-lightweight-request-inspector-with-middleware-1) [ ![Laravel Reverb WebSocket Presence Channels: Private State Without a Redis Bottleneck](https://cdn.msaied.com/285/4691db3cdad180d19e485611a8732087.png) laravel reverb websockets 

### Laravel Reverb WebSocket Presence Channels: Private State Without a Redis Bottleneck

Presence channels in Laravel Reverb let you track who is online without hammering Redis on every heartbeat. He...

  ![Mohamed Said](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MJ.jpg)  Mohamed Said 

 24 Jun 2026     4 min read  

  Read    

 ](https://msaied.com/articles/laravel-reverb-websocket-presence-channels-private-state-without-a-redis-bottleneck) 

   [  ![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)
