Lightweight Laravel Request Inspector with Tagged Cache | Mohamed Said       [Skip to content](#main)  [ ![](https://cdn.msaied.com/01KT78WE565VEMM3PSNQAAB0MH.png) Mohamed SaidLaravel Backend Engineer ](https://www.msaied.com/public) - [Home](https://www.msaied.com/public)
- [Projects](https://www.msaied.com/public/projects)
- [Articles](https://www.msaied.com/public/articles)
- [Certificates](https://www.msaied.com/public/certificates)
- [About](https://www.msaied.com/public#about)

           [  Contact](https://www.msaied.com/public#contact) Menu 

Menu
----

Close 

 - [HomeStart here](https://www.msaied.com/public)
- [ProjectsCase studies](https://www.msaied.com/public/projects)
- [ArticlesEngineering notes](https://www.msaied.com/public/articles)
- [CertificatesCredentials](https://www.msaied.com/public/certificates)
- [AboutHow I work](https://www.msaied.com/public#about)
- [ContactGet in touch](https://www.msaied.com/public#contact)

  [Start a conversation](https://www.msaied.com/public#contact) [WhatsApp](https://wa.me/201094619204) [Email](mailto:hello@msaied.com) 

 1. [Home](https://www.msaied.com/public)
2. /
3. [Articles](https://www.msaied.com/public/articles)
4. /
5. Laravel Telescope Alternatives: Building a Lightweight Request Inspector with Tagged Cache

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

 Telescope is invaluable in development, but its overhead makes it unsuitable for production. Learn how to build a focused, low-overhead request inspector using Laravel's tagged cache, middleware, and a Filament panel.

 ![](https://cdn.msaied.com/01M22N44A70A5MC2S599JP0MPH.webp) [Mohamed Said](https://www.msaied.com/public#person) Published 25 Jun 2026 · Updated 25 Jun 2026 · 4 min read

ShareCopy linkCopied

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

  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)

 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.

- [laravel](https://www.msaied.com/public/articles?search=laravel)
- [filament](https://www.msaied.com/public/articles?search=filament)
- [performance](https://www.msaied.com/public/articles?search=performance)
- [debugging](https://www.msaied.com/public/articles?search=debugging)
- [middleware](https://www.msaied.com/public/articles?search=middleware)

 Frequently asked questions 
---------------------------

  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.

   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.

   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.

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

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

[About](https://www.msaied.com/public#about) [GitHub ↗](https://github.com/EG-Mohamed) [LinkedIn ↗](https://www.linkedin.com/in/msaiedm/) [WhatsApp ↗](https://wa.me/201094619204) [Email Address ↗](mailto:hello@msaied.com) [My CV ↗](https://drive.google.com/file/u/0/d/1MF20IPRJyzfy32mhEutjL5EpSls0w2Q8/view)  

   [Previous articleLaravel Telescope Alternatives: Building a Lightweight Request Inspector with Middleware](https://www.msaied.com/public/articles/laravel-telescope-alternatives-building-a-lightweight-request-inspector-with-middleware-1) [Next articleLaravel Queues: Job Middleware for Idempotency, Rate Limiting, and Graceful Failure](https://www.msaied.com/public/articles/laravel-queues-job-middleware-for-idempotency-rate-limiting-and-graceful-failure)  

   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)

 ###  Have a technical challenge?

 Tell me what you’re building. I reply within two working days.

[Start a conversation](https://www.msaied.com/public#contact) 

   Related articles
-----------------

 [ ![](https://cdn.msaied.com/740/cce86edc21eddcbdd2f2454fadaf9c70.png)  · 3 min read### The Pipeline Pattern in Laravel: Custom Pipelines Beyond Middleware

5 Oct 2026 ](https://www.msaied.com/public/articles/the-pipeline-pattern-in-laravel-custom-pipelines-beyond-middleware-1) [ ![](https://cdn.msaied.com/739/2d6897fdcdcf090613f96f72a64b8a78.png)  · 4 min read### MySQL Full-Text Search in Laravel: Indexes, Relevance Scoring, and Boolean Mode

4 Oct 2026 ](https://www.msaied.com/public/articles/mysql-full-text-search-in-laravel-indexes-relevance-scoring-and-boolean-mode) [ ![](https://cdn.msaied.com/738/073696a3fefe18bec825beec5ac658f5.png)  · 4 min read### Laravel Queue Rate-Limited Middleware: Throttling Jobs Without Losing Work

4 Oct 2026 ](https://www.msaied.com/public/articles/laravel-queue-rate-limited-middleware-throttling-jobs-without-losing-work) 

  Have a technical challenge?
----------------------------

Tell me what you’re building. I reply within two working days.

 [Discuss your project ↗](https://www.msaied.com/public#contact) 

  © 2026 Mohamed Said · Built with Laravel, meant to last.Senior Backend Engineer specializing in Laravel, scalable SaaS platforms, APIs, and cloud infrastructure. I build secure, high-performance web applications that help businesses grow.

 - [Home](https://www.msaied.com/public)
- [Articles](https://www.msaied.com/public/articles)
- [Certificates](https://www.msaied.com/public/certificates)
- [GitHub](https://github.com/EG-Mohamed)
- [LinkedIn](https://www.linkedin.com/in/msaiedm/)
- [WhatsApp](https://wa.me/201094619204)
- [Email Address](mailto:hello@msaied.com)
- [My CV](https://drive.google.com/file/u/0/d/1MF20IPRJyzfy32mhEutjL5EpSls0w2Q8/view)
- [Sitemap](https://www.msaied.com/public/sitemap.xml)
