Connect CodeIgniter 4 applications to the Inspector monitoring dashboard.
This library was built in collaboration with Prysis - [email protected]
Install the latest version using the composer command below:
composer require inspector-apm/inspector-codeigniter
Run the install command to publish the Inspector.php
configuration file in your application app/Config
directory:
php spark inspector:install
Add the environment variable below to your .env
file in order to make your application able to send data to your dashboard.
You can get a new Ingestion Key by creating a new app in your account: https://app.inspector.dev
#--------------------------------------------------------------------
# INSPECTOR
#--------------------------------------------------------------------
inspector.ingestionKey = '974yn8c34ync8xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
The package provides your application with the inspector
filter that you can use to monitor
incoming HTTP requests.
We highly recommend to add inspector
to the global filters in your app/Config/Filter.php
configuration class
in order to monitor all HTTP requests:
class Filters extends BaseFilters
{
/**
* List of filter aliases that are always
* applied before and after every request.
*
* @var array<string, array<string, array<string, string>>>|array<string, list<string>>
*/
public array $globals = [
'before' => [
...,
'inspector',
],
'after' => [
...,
'inspector',
],
];
}
You can eventually turn off monitoring using the
ignoreRoutes
configuration property: https://docs.inspector.dev/guides/codeigniter/configuration#ignore-routes
Run the command below to check if your system is properly configured. If all checks are green you can deploy the update in your production environment.
php spark inspector:test
We highly recommend adding the helper in the Config/Autoload.php
configuration class to make it available
globally into the application:
class Autoload extends AutoloadConfig
{
/**
* -------------------------------------------------------------------
* Helpers
* -------------------------------------------------------------------
* Prototype:
* $helpers = [
* 'form',
* ];
*
* @var list<string>
*/
public $helpers = ['inspector'];
}
The helper provides a shortcut to the inspector instance to monitor custom code blocks or manually report specific exceptions.
// Load the helper if you haven't added it to Autoload.php
helper('inspector');
// Monitor custom code blocks
$json = inspector()->addSegment(function () {
return file_get_contents('auth.json');
}, 'http', 'READ auth.json');
// Report an exception
inspector()->reportException(new \Exception("Whoops there's an error here."));
Check out the official documentation
We encourage you to contribute to Inspector! Please check out the Contribution Guidelines about how to proceed. Join us!
This package is licensed under the MIT license.