Laravel Real-Time performance monitoring & alerting using Inspector

Hi, I’m Valerio Barbera software engineer and Laravel — certified developer based in Naples, Italy.

As product owner I learned on my skin how an application issue isn’t just a technical stuff. For software-driven companies errors could create a negative impact on the users experience and on their perception about our product and work.

Users don’t spend their time to report bugs, they just stop using our application, checking for another one that fits their needs better.

I’m one of those that publish new code changes almost every day and unfortunately it’s quite impossible to anticipate all the problems that could happen after every update.

In most of the projects I’ve worked on the 50% of the drawbacks for users were caused by simple code mistakes, often in the code executed in background where it’s even more tricky to know if all is working fine or something is broken, and the more the application grows the more difficult it is to avoid these incidents.

Thanks to Inspector I no longer need to spend a lot of time to search errors inside logs manually, trying to anticipate users complaints, because an autonomous tool is doing this job for me, making it rise to the surface anything that could create problems for users immediately.

Inspector is a composer package to add real-time monitoring & exception alerting in Laravel applications, it’s very easy to install and use, and it takes just two minutes to get started.

Let me show you how it works.

Install the composer package

Run the composer command below in your terminal:

composer require inspector-apm/inspector-laravel

Configure the API key

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

Select and copy the API key:

Screen after “create a project”

Put the API key into your environment file:


By default Inspector will monitor:

  • Database interactions
  • Queued Jobs
  • Artisan commands
  • Unhandled Exceptions

We just turned on the light in the 50% of our app executed in background. The next step is to monitor all transactions generated by user interactions.

Incoming Web Requests inspection

To activate inspection also when your app is executed due to an incoming http request you can use the WebRequestMonitoring middleware.

It works like any other Laravel middleware you are familiar to so you are free to decide which routes need to be monitored based on your routes configuration or on your personal monitoring preferences.

The most easy way to cover all your application routes is attaching the middleware in the Http\Kernel class.


use Inspector\Laravel\Middleware\WebRequestMonitoring;

 * The application's route middleware groups.
 * @var  array
protected $middlewareGroups = [
    'web' => [

    'api' => [

Instantly you will see transaction streams in your project’s dashboard:

and for each transaction you can monitor what your application is executing in real-time:

Enrich your timeline

You can add custom spans in your timeline to measure the impact that an hidden code block has on a transaction’s performance.

Suppose you have a queued job that executes some database checks and an http request to an external service in background.

Job and queries are reported automatically, but it could be interesting to monitor and measure the execution of the http request. Simply use the Inspector facade:


use Inspector\Laravel\Facades\Inspector;

class TagUserAsActive extends Job
    protected $user;

     * Monitoring & Measure an external http request
    public function handle()
        try {
            // Start monitoring
            $segment = Inspector::startSegment('http');
            $this->guzzle->post('[mail-marketing-url]/add_tag', [
                'email' => $htis->user->email,
                'tag' => 'active',
        } catch (GuzzleException $exception) {
        } finally {
            // End monitoring

You will see the impact of the new segment in your timeline:

New “http” segment appear in the timeline

Exceptions Alerting

By default, every unhandled exception fired in your Laravel app will be reported automatically to be sure you’re alerted for unpredictable errors in real time.

I wish that every change I make to my code could be perfect. But the reality is, this is not always the case. Some errors appear immediately after an update, while others pop up unpredictably.

However, Inspector automates the detection of unknown issues so I no longer need to manually check the status of my apps continuously or wait reports directly from users. If something goes wrong I’ll receive a notification in real time, and after each release I can stay informed about the impact of the latest code refactor.

If your code fires an exception but you don’t want to block the execution, you can report the error to inspector manually for private monitoring about availability of the external system.


try {
	// Your dangerous http call here...
} catch (\Exception $exception) {
    // Report an exception intentionally to collect diagnostics data

Furthermore, if the http request fails, you will be alerted in real time in your inbox to take a look at the error as it appears.

Real-Time email notification

You even get access to detailed information gathered by Inspector in real time:


When a customer reports to you that something isn’t working, it forces you to drop whatever you are doing and start trying to reproduce the scenario, then recapture and reanalyze the logs in your own toolset.

Getting a true picture of what’s happening can require hours or, based on my experience, even days. Inspector can make a huge difference in terms of efficiency and productivity.

By delegating bug discovery to an automatic monitoring tool, allows you to solve 90% of the problems in the half the time, before users even know about them.

Find out how Inspector metrics helps you to make data-driven decisions to move your application forward avoiding errors & exceptions.

Don't wait for user reports to know if your back-end is in trouble.

Try Inspector Now