Installation

How to connect your CodeIgniter application to Inspector.

Requirements

  • PHP >= 7.4

  • CodeIgniter >= 4

Installation

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

Configure The Ingestion Key

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'

HTTP Request Monitoring

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
     */
    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

Verify And Deploy

Run the command below to check if your system is properly configured. If all checks are green you can deploy in your production environment.

php spark inspector:test

If everything is "green" you can release the update in your production environment.

By default Inspector will monitor:

  • Http Requests

  • Spark Commands

  • Database queries

  • Unhandled Exceptions

In the next sections you can learn how to further customize the library behaviour.

Helper

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."));

Learn more about custom Segments here: https://docs.inspector.dev/guides/raw-php/custom-segments

Last updated