Inspector logo

Installation

Welcome to the Inspector developer documentation. Inspector is a composer package to add real time monitoring & exception alerting in your Laravel application.

It doesn't need anything at server level. You can add Inspector to your application via composer like any other dependencies, so it's a perfect solution if you are running your app in a managed server like Cloudways, RunCloud or similar, or you are not in confort installing and maintaining OS level softwares like me.

This documentation will help you to start working with Inspector in just a few minutes, as well as support if you get stuck.

{success} Consider to read our getting started article to speed up initial approach.


Version Compatibility

Laravel Inspector package
5.x 2.x
6.x 3.x

Installing Inspector

Install the latest version of our Laravel 6.x package by:

composer require inspector-apm/inspector-laravel

If your application is using a 5.x version of the Laravel framework use the command below:

composer require "inspector-apm/inspector-laravel=^2.0"

Configure the API key

Get a fresh API key by signing up for Inspector (https://app.inspector.dev/register) and creating a new application.

Put the Inspector API key in your environment file.

INSPECTOR_API_KEY=[api key]

By default Inspector will monitor everything executed in background:

  • Queued Jobs
  • Artisan commands
  • Unhandled Exceptions

Test everything is working

Create a test route that simply fires an unhandled exception. In your routes/web.php file paste the code below:

Route::get('test', function () {
    throw new \Exception('First Exception detected'));
});

Open this route in you browser to test the connection between your app and Inspection API. You should receive your first notification about exception detection.

Monitoring Http Requests

You can use the WebRequestMonitoring middleware to activate inspection when your application is executed by an incoming http request. 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.

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

Attach to middleware group

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

use Inspector\Laravel\Middleware\WebRequestMonitoring;

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

    'api' => [
        ...,
        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.

Use as middleware key

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

/**
 * Create new middleware key.
 */
protected $routeMiddleware = [
    ...,
    'inspector' => WebRequestMonitoring::class,
];

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