Laravel 11 – Inspector Upgrade Guide

Valerio Barbera

In this article I’ll show you how to upgrade your Inspector SDK configuration to work with Laravel 11, the latest version of the framework released just yesterday.

The Inspector SDK was updated to meet the requirements of the Symfony terminable interface and it’s now compatible with Laravel 11. The official documentation was updated as well: https://docs.inspector.dev

Laravel 11 brings a number of changes to the previous version. One of the most significant is the absence of the App\Http\Kernel class. The properties of this component have been moved into the new version of the bootstrap/app.php file that now is a bit more interactive and it’s the new place where you configure the middleware for your application.

For detailed information about the release of Laravel Reverb, the changes to model cast, and the new directory structure you can read the official announcement on Laravel News.

Basically the middleware configuration is the only change you had to do to make Inspector work upgrading your Laravel installation to v11. Everything else continues to work as usual.

Append middleware to Laravel 11 middleware groups

Until yesterday the center of middleware configuration was the App\Http\Kernel class.

/**
 * The application's route middleware groups.
 *
 * @var  array
 */
protected $middlewareGroups = [
    'web' => [
        ...,
        \Inspector\Laravel\Middleware\WebRequestMonitoring::class,
    ],
    'api' => [
        ...,
        \Inspector\Laravel\Middleware\WebRequestMonitoring::class,
    ]
]

Now you should instruct Laravel to append the Inspector middleware to the web and api middleware groups in the bootstrap/app.php file:

use \Inspector\Laravel\Middleware\WebRequestMonitoring;
return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        // routes
    )
    ->withMiddleware(function (Middleware $middleware) {
        // Append the middleware
        $middleware->appendToGroup('web', WebRequestMonitoring::class)
            ->appendToGroup('api', WebRequestMonitoring::class);
    })
    ->withExceptions(function (Exceptions $exceptions) {
        //
    })->create();

This guarantees you to also catch the authenticated user that will automatically be attached to the current transaction.

Inspector timeline Laravel 11

Assigning middleware to routes

In alternative you can assign the middleware to specific routes or groups. This type of usage is the same for current and previous versions of the framework.

/*
 * Attach the "inspector" middleware in your routes
 */
Route::middleware(\Inspector\Laravel\Middleware\WebRequestMonitoring::class)
    ->group(function () {
        // Monitored routes here
    });

Create a custom middleware

If you want to customize the behavior of the monitoring middleware you can create a custom middleware class that extend the original Inspector middleware:

php artisan make:middleware

In the new middleware class extend the Inspector middleware so you can override its methods and implement your customizations. This is the recommended way to implement custom logic to ignore requests. Read more in the documentation.

Once you have the custom middleware you have to register it instead of the original Inspector middleware.

use App\Http\Middleware\InspectorFilterMonitoringMiddleware;
return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        // routes
    )
    ->withMiddleware(function (Middleware $middleware) {
        // Append the custom middleware
        $middleware->appendToGroup('web', InspectorFilterMonitoringMiddleware::class)
            ->appendToGroup('api', InspectorFilterMonitoringMiddleware::class);
    })
    ->withExceptions(function (Exceptions $exceptions) {
        //
    })->create();

New to Inspector? Try it for free now

Are you responsible for application development in your company? Monitor your software products with Inspector for free. You can find out bugs and bottlenecks in your code automatically, before your customers stumble onto the problem.

Inspector is usable by developers of all skills level. If you want effective automation, deep insights, and the ability to forward alerts and notifications into your messaging environment try Inspector for free. Register your account.

Or learn more on the website: https://inspector.dev

Related Posts

Laravel Redis Throttle In Details: Tutorial

Redis Throttle is a fantastic feature provided by the Redis facade in the Laravel framework. It’s a convenient way to limit the rate at which certain actions can be performed. How Laravel Redis throttle works The throttle() method allows you to go through the following process:  What is an Atomic Lock in Redis An atomic

The Value Of Data: A Guide To Informed Decision-Making

What is the value of data? That is a huge question. I could go down so many different rabbit holes and make nuanced points about why data’s valuable. At a very high level the value of data is that it lowers your level of uncertainty when it comes time to make a decision or solve

Monitoring Agent: Elevate Your Observability With Inspector

The last fundamental concept to fully evaluate whether, and how, to invest in a monitoring stack is the type of monitoring agent. Very briefly, a monitoring system is always composed of two elements. The agent, which is a software package that you must install in your application or infrastructure. And the dashboard to view the