Http Requests Monitoring

To activate inspection when your application is executed by an incoming http request you can use the WebRequestMonitoring middleware.

Thanks to the middleware you are free to decide on which routes you want activate execution tracing, based on your routes configuration or on your personal monitoring preferences. WebRequestMonitoring middleware works like any other Laravel middleware you are familiar to.

To get more information on how middlewares works in Laravel, take a look at Laravel's official documentation.

Basically you can attach the middleware in the App\Http\Kernel class in one or more of your predefined middleware groups:

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

Usually web and api middleare groups are wrapping your entire application, so in two lines of code you can monitoring all incoming http requests.

Option 2 - Use as middleware key

In alternative you can create a middleware key so you can attach it in a specific route or group:

/*
* Create a new middleware key (inspector) in your \App\Http\Kernel class.
*/
protected $routeMiddleware = [
...,
'inspector' => \Inspector\Laravel\Middleware\WebRequestMonitoring::class,
];

Use "inspector" middleware key in you routes:

/*
* Attach the "inspector" middleware in your routes
*/
Route::prefix('app')->middleware('inspector')->group(function () {
...
});

Ignore Web Requests

Inspector provide a basic strategy to ignore execution cycles that you don't want report in your dashboard, but the middleware is designed to allows you to extend it and add your own strategy overwriting shouldRecorded method that should return a boolean result to establish if the request should be recorded or not.

Run the artisan command below to create a new middleware class:

php artisan make:middleware InspectorFilterMonitoringMiddleware

In the new middleware class just override shouldRecorded method to implement your filtering strategy:

<?php
use \Inspector\Laravel\Middleware\WebRequestMonitoring;
class InspectorFilterMonitoringMiddleware extends WebRequestMonitoring
{
/**
* Determine if Inspector should record current request.
*
* @param \Illuminate\Http\Request $request
* @return bool
*/
protected function shouldRecorded($request): bool
{
return $request->userAgent() === 'Reliable User Agent';
}
}