CodeIgniter SDK
The Nadi CodeIgniter SDK provides integration with CodeIgniter 4 applications, automatically capturing exceptions and providing CodeIgniter-specific context.
Requirements
- PHP 8.1 or higher
- CodeIgniter 4.3+
- Composer
Installation
Install the package via Composer:
composer require nadi-pro/nadi-codeigniterRun the installation command:
php spark nadi:installThis command will:
- Publish the configuration file to
app/Config/Nadi.php - Download and install the Nadi Shipper binary to
vendor/bin/ - Create the
writable/nadi/directory for log files - Download the latest shipper configuration from GitHub
- Prompt for your API credentials (can be skipped)
- Save
NADI_API_KEYandNADI_APP_KEYto your.envfile - Display Supervisord setup instructions
Interactive Credential Setup
During installation, you'll be prompted to enter:
- API Key - Create one at API Tokens
- App Key - Available on your application page (e.g.,
https://nadi.pro/applications/<your-app-uuid>)
Press Enter to skip and configure later.
Service Registration
Register the Nadi service in your app/Config/Services.php or call it in your app/Config/Boot/production.php:
// app/Config/Boot/production.php
\Nadi\CodeIgniter\NadiService::register();Filter Setup
Add the Nadi filter to your app/Config/Filters.php to capture request context:
// app/Config/Filters.php
namespace Config;
use CodeIgniter\Config\Filters as BaseFilters;
class Filters extends BaseFilters
{
public array $aliases = [
// ... other filters
'nadi' => \Nadi\CodeIgniter\Filters\NadiFilter::class,
];
public array $globals = [
'before' => [
'nadi',
],
];
}Configuration
Add your credentials to .env:
NADI_ENABLED=true
NADI_DRIVER=log
NADI_API_KEY=your-api-key
NADI_APP_KEY=your-application-keyThe configuration file app/Config/Nadi.php provides additional options:
// app/Config/Nadi.php
namespace Config;
use CodeIgniter\Config\BaseConfig;
class Nadi extends BaseConfig
{
public bool $enabled = true;
public string $driver = 'log';
public string $apiKey = '';
public string $appKey = '';
public array $scrubFields = [
'password',
'password_confirmation',
'credit_card',
'cvv',
'ssn',
'api_key',
'secret',
];
}Shipper Setup
The shipper binary monitors writable/nadi/ for log files and forwards them to the Nadi API. Set up Supervisord to run the shipper as a background process.
Create a supervisor config file:
sudo nano /etc/supervisor/conf.d/nadi-shipper.confAdd the configuration (paths are shown during installation):
[program:nadi-shipper-your-app]
process_name=%(program_name)s
command=/path/to/project/vendor/bin/shipper --config=/path/to/project/writable/nadi/nadi.yaml
directory=/path/to/project
autostart=true
autorestart=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/path/to/project/writable/logs/shipper.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=3
stopwaitsecs=3600Apply the configuration:
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start nadi-shipper-your-appBasic Usage
Automatic Exception Capturing
Once installed, Nadi automatically captures all unhandled exceptions. No additional code is required.
// This exception will be automatically captured
throw new \Exception('Something went wrong');Manual Exception Capturing
You can also capture exceptions manually:
use Nadi\CodeIgniter\Facades\Nadi;
try {
// Your code
} catch (\Exception $e) {
Nadi::captureException($e);
// Handle the exception
}Capturing Messages
Log messages without an exception:
use Nadi\CodeIgniter\Facades\Nadi;
Nadi::captureMessage('User performed an important action', 'info');Available levels: debug, info, warning, error, fatal
Adding Context
User Context
Identify the current user:
use Nadi\CodeIgniter\Facades\Nadi;
Nadi::setUser([
'id' => session()->get('user_id'),
'email' => session()->get('email'),
'name' => session()->get('name'),
]);Tags
Add tags for filtering:
use Nadi\CodeIgniter\Facades\Nadi;
Nadi::setTag('subscription', 'premium');
Nadi::setTags([
'feature' => 'checkout',
'version' => '2.1.0',
]);Extra Data
Attach additional data:
use Nadi\CodeIgniter\Facades\Nadi;
Nadi::setExtra('order_id', $order->id);
Nadi::setExtras([
'cart_items' => count($cartItems),
'total' => $cartTotal,
]);What's Captured
The CodeIgniter SDK automatically captures:
| Data | Description |
|---|---|
| Exception | Type, message, code, file, line |
| Stack Trace | Full trace with file paths and line numbers |
| Request | URL, method, headers, input (filtered) |
| User | Authenticated user (if configured) |
| Session | Session data (filtered) |
| Environment | App environment, PHP version, CodeIgniter version |
| Route | Controller, method, parameters |
| Git | Commit hash (if available) |
Filtering Sensitive Data
Configure which request fields to exclude in app/Config/Nadi.php:
public array $scrubFields = [
'password',
'password_confirmation',
'credit_card',
'cvv',
'ssn',
'api_key',
'secret',
];Spark Commands
# Install Nadi and setup shipper
php spark nadi:install
# Test the API connection
php spark nadi:test
# Verify the App Key
php spark nadi:verify
# Update the shipper binary
php spark nadi:update-shipperNext Steps
- PHP SDK — Advanced Usage - Advanced features available in all PHP SDKs
- PHP SDK — Transporters - Configure transport options
- PHP SDK — Sampling - Control event volume
- Shipper - Shipper agent documentation