visit
Users don't spend their time to report bugs, they just stop using our application, moving to 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 release.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 (artisan commands or Jobs) where it's even more tricky to know if all is working fine or something is broken.Inspector is a composer package to add real-time monitoring in Laravel applications, it's very easy to install and use, and it takes just two minutes to get started.Thanks to Inspector you'll no longer need to spend a lot of time to monitor your application behaviour by logs manually, because an autonomous tool does this job for you 24/7, making it rise to the surface anything that could create problems for users.Let me show you how it works.Install the composer package
Install our package by running the 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 () and creating a new application, it takes just a few seconds. You'll see installation instructions directly in the app screen:INSPECTOR_API_KEY=13c37c434XXXXXXXXXXXX
Execute our test command to check if your app send data to inspector correctly:
php artisan inspector:test
The most easy way to cover all your application routes is attaching the middleware in the
App\Http\Kernel
class.<?php
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
...,
\Inspector\Laravel\Middleware\WebRequestMonitoring::class,
],
'api' => [
...,
\Inspector\Laravel\Middleware\WebRequestMonitoring::class,
]
]
Enrich your timeline
Inspector monitors database query, background jobs, artisan commands by default, but could be many critical statements in your code that need to be monitored in terms of performance and error:Thanks to our package you can add custom segments in your timeline in addition to those detected by default, to measure the impact that an hidden code block has on a transaction’s performance.
Let me show you a real life example.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 helper function:<?php
class TagUserAsActive extends Job
{
/**
* @param User $user
*/
protected $user;
/**
* Monitoring & Measure an external http request
*/
public function handle()
{
// Start monitoring
inspector()->addSegment(function () {
$this->guzzle->post('[mail-marketing-url]/add_tag', [
'email' => $htis->user->email,
'tag' => 'active',
]);
}, 'http');
}
}
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.<?php
try {
// Your dangerous http call here...
} catch (\Exception $exception) {
// Report an exception intentionally to collect diagnostics data
Inspector::reportException($exception)
}
Previously published at