1eonardo-dev / monitoring-client
PHP client for reporting events (crash/exception/log) to Monitoring Platform.
Requires
- php: ^7.4 || ^8.0
Requires (Dev)
- phpunit/phpunit: ^9.6 || ^10.5 || ^11.0 || ^12.0
Suggests
- laravel/framework: To use the Laravel ServiceProvider/Facade (LeonardoDev\Monitoring\Laravel)
- yiisoft/yii2: To use the Yii2 component (LeonardoDev\Monitoring\Yii2)
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-20 20:04:39 UTC
README
A lightweight PHP client for reporting events (crashes, exceptions, logs) to Monitoring Platform.
- No mandatory dependencies — runs in any PHP 7.4+ project.
- Never throws — a network failure is logged via
error_log()and the method returnsfalse, so your application never breaks while reporting. - Stream-based HTTP transport — no
curlrequired. - Optional framework adapters for Laravel and Yii2.
The Laravel/Yii2 adapter classes are only loaded if the corresponding framework is installed (lazy autoloading +
suggestincomposer.json), so they never break plain-PHP projects.
The two packages
This package targets modern PHP projects. If you still run PHP 5, use the legacy package instead:
| Package | PHP | Framework adapters | Type hints |
|---|---|---|---|
1eonardo-dev/monitoring-client |
7.4+ | Laravel & Yii2 | Yes |
1eonardo-dev/monitoring-client-legacy |
5.6+ | None (pure PHP) | No |
Requirements
- PHP 7.4 or later.
Installation
composer require 1eonardo-dev/monitoring-client
Quick start
use LeonardoDev\Monitoring\MonitoringClient; $monitoring = new MonitoringClient( 'https://monitoring.your-company.com', 'mp_...', 'php', '1.0.0', ); try { // your code } catch (\Throwable $e) { $monitoring->captureException($e); } $monitoring->captureMessage('Something weird happened', 'warning');
API
MonitoringClient
| Method | Description |
|---|---|
captureException(\Throwable $e, array $context = [], ?string $level = null): bool |
Report an exception. |
captureMessage(string $message, string $level = 'info', array $context = []): bool |
Report a log message. |
captureEvent(Event $event): bool |
Report a custom event. |
send(array $data): bool |
Low-level send with a raw payload. |
DTOs
Event— value object for the event payload (type,level,message,platform,version,fingerprint,context).Config— groups the connection parameters (baseUrl,apiKey,platform,version,timeoutSeconds,path).
use LeonardoDev\Monitoring\Config; use LeonardoDev\Monitoring\Event; use LeonardoDev\Monitoring\MonitoringClient; $client = MonitoringClient::fromConfig(new Config( 'https://monitoring.your-company.com', 'mp_...', 'php', '1.0.0', )); $client->captureEvent(new Event('custom', 'warning', 'something happened'));
Custom endpoint path
By default events are sent to {baseUrl}/api/v1/events. You can change the
path via the path argument (or the path key in Config::fromArray):
$monitoring = new MonitoringClient( 'https://monitoring.your-company.com', 'mp_...', 'php', '1.0.0', 2, '/api/custom/ingest', );
Laravel integration
The package auto-discovers its service provider and facade. Optionally publish the config:
php artisan vendor:publish --tag=monitoring-config
Add to your .env:
MONITORING_URL=https://monitoring.your-company.com MONITORING_API_KEY=mp_... MONITORING_API_PATH=/api/v1/events
Then use the facade:
use LeonardoDev\Monitoring\Laravel\Monitoring; try { // your code } catch (\Throwable $e) { Monitoring::captureException($e); }
Yii2 integration
'components' => [ 'monitoring' => [ 'class' => \LeonardoDev\Monitoring\Yii2\MonitoringComponent::class, 'url' => getenv('MONITORING_URL'), 'apiKey' => getenv('MONITORING_API_KEY'), ], ], // Usage: Yii::$app->monitoring->exception($e);
Custom transport
Implement LeonardoDev\Monitoring\Transport\Transport to use your own HTTP
client (Guzzle, cURL, etc.):
use LeonardoDev\Monitoring\MonitoringClient; use LeonardoDev\Monitoring\Transport\Transport; class GuzzleTransport implements Transport { public function send(string $url, string $body, array $headers): ?array { // ... return ['status' => int, 'body' => string], or null on failure. } } $client = new MonitoringClient( 'https://monitoring.your-company.com', 'mp_...', 'php', null, 2, '/api/v1/events', new GuzzleTransport(), );
Tests
composer install
composer test
Changelog
See CHANGELOG.md.
License
MIT. See LICENSE.