laravel-monitor maintained by prmgtk
prmgtk/laravel-monitor
Report errors from any Laravel site to the prmgtk error-monitoring platform. English | العربية
English
What it does
- Captures every reportable exception automatically (Laravel's own
dontReportlist is respected, normal logging is untouched), including fatal errors and failed queue jobs. - Groups, de-duplicates and throttles reports, scrubs secrets, and sends them to prmgtk without slowing the site (after the response, 1.5 s timeout).
- Never breaks your app: every code path is wrapped, with a re-entrancy guard, a local circuit breaker and graceful degradation when the cache or the network is down.
Requirements
PHP 8.1+ and Laravel 10, 11, 12 or 13.
Installation
Option 1 - Packagist (once published)
composer require prmgtk/laravel-monitor
Option 2 - GitHub (VCS repository) - add to the host app's composer.json:
{
"repositories": [
{ "type": "vcs", "url": "https://github.com/WaelMz/prmgtk-laravel-monitor" }
],
"require": {
"prmgtk/laravel-monitor": "^1.0"
}
}
then run composer update prmgtk/laravel-monitor.
Option 3 - local path
{
"repositories": [
{ "type": "path", "url": "../laravel-monitor", "options": { "symlink": true } }
],
"require": {
"prmgtk/laravel-monitor": "*"
}
}
The service provider and the PrmgtkMonitor facade alias are auto-discovered.
Setup
php artisan prmgtk-monitor:install # publishes config, adds the keys to .env and .env.example
PRMGTK_MONITOR_KEY=prm_xxxxxxxxxxxxxxxx
PRMGTK_MONITOR_URL=https://prmgtk.com
The secret site key is provided to you by prmgtk. Keep it only in .env and never commit it.
By default only the production environment reports. To test from another environment set PRMGTK_MONITOR_ENVIRONMENTS=production,staging (or leave it empty for all), then verify:
php artisan prmgtk-monitor:test
It checks the config, pings the platform and sends a clearly labelled "prmgtk monitor test exception". It works even if the current environment is not in the list (a notice is shown; --force hides it).
Configuration reference (config/prmgtk-monitor.php)
| Option | Env | Default | Description |
|---|---|---|---|
enabled |
PRMGTK_MONITOR_ENABLED |
true |
Master switch |
key |
PRMGTK_MONITOR_KEY |
- | Secret site key (prm_...) |
url |
PRMGTK_MONITOR_URL |
https://prmgtk.com |
Base URL or full ingest URL (normalized) |
environments |
PRMGTK_MONITOR_ENVIRONMENTS |
production |
Comma list, wildcards allowed; empty = all |
min_level |
PRMGTK_MONITOR_MIN_LEVEL |
error |
info, warning, error, critical |
timeout / connect_timeout |
PRMGTK_MONITOR_TIMEOUT / ..._CONNECT_TIMEOUT |
1.5 / 1.0 |
Seconds |
send_after_response |
PRMGTK_MONITOR_SEND_AFTER_RESPONSE |
true |
Send in the terminating phase (console sends immediately) |
queue.enabled |
PRMGTK_MONITOR_QUEUE_ENABLED |
false |
Dispatch a queued job instead |
queue.connection / queue.name |
PRMGTK_MONITOR_QUEUE_CONNECTION / PRMGTK_MONITOR_QUEUE |
null |
Queue connection and queue name |
ignore_http_4xx |
- | true |
Skip HTTP exceptions with 4xx status |
dont_report |
- | [] |
Extra exception classes to ignore |
ignore_messages |
- | [] |
Regexes matched against the message |
throttle_seconds |
PRMGTK_MONITOR_THROTTLE_SECONDS |
60 |
Same fingerprint at most once per window per server (0 = off) |
max_reports_per_minute |
PRMGTK_MONITOR_MAX_PER_MINUTE |
30 |
Local circuit breaker (0 = off) |
cache_store |
PRMGTK_MONITOR_CACHE_STORE |
default store | Store for throttle/pause flags |
scrub_fields |
- | password, token, secret, ... | Keys replaced by [filtered] (substring match, recursive) |
capture.request_body / capture.headers / capture.user |
- | true |
What request data is attached |
trace_frames |
- | 60 |
Max stack frames |
release / release_from_git |
PRMGTK_MONITOR_RELEASE / PRMGTK_MONITOR_RELEASE_FROM_GIT |
- / false |
Release label (or short git SHA from .git/HEAD) |
context |
- | null |
Hook returning extra context |
before_send |
- | null |
Hook to modify the payload or return null to drop it |
Hooks accept a Closure, an invokable class name, or Class@method. Closures cannot be used if you run config:cache; use a class instead.
// config/prmgtk-monitor.php
'context' => App\Monitoring\ExtraContext::class, // fn (?Throwable $e): array
'before_send' => App\Monitoring\BeforeSend::class, // fn (array $payload, ?Throwable $e): ?array
Manual capture
use Prmgtk\Monitor\Facades\PrmgtkMonitor;
try {
$gateway->charge($order);
} catch (Throwable $e) {
PrmgtkMonitor::captureException($e, ['order_id' => $order->id]); // level auto-detected
PrmgtkMonitor::captureException($e, ['order_id' => $order->id], 'warning');
}
PrmgtkMonitor::captureMessage('Payment gateway is slow', 'warning', ['ms' => 3200]);
$ok = PrmgtkMonitor::ping(); // array (decoded response) or false
Manual captures bypass dont_report / ignore_http_4xx but still honour the environment, level, throttle and circuit-breaker rules.
Log channel
// config/logging.php
'channels' => [
'prmgtk' => ['driver' => 'prmgtk', 'level' => 'error'],
'stack' => ['driver' => 'stack', 'channels' => ['daily', 'prmgtk']],
],
Records that carry an exception in their context use it. Exceptions already captured by the handler are not sent twice.
Queue mode
PRMGTK_MONITOR_QUEUE_ENABLED=true
PRMGTK_MONITOR_QUEUE_CONNECTION=redis
PRMGTK_MONITOR_QUEUE=monitoring
Run a worker for that queue. The job never fails loudly and never retries.
Privacy and scrubbing
- Request body, query, headers and context are scrubbed recursively: keys containing
password,token,secret,api_key,authorization,cookie,card,cvv, ... become[filtered]. Authorization,Cookie,X-CSRF-*andX-XSRF-*headers are never sent. Uploaded files are replaced by[file: name, size].- Only the user's
idandemailare sent. File paths are relative tobase_path(); the server layout is not sent, only a short hash (runtime.base_path_hash). - Large values are truncated and the whole payload is kept under 250 KB. The platform scrubs again on receipt and stores IPs only as a hash.
- Disable parts with
capture.request_body,capture.headers,capture.user.
Troubleshooting
- Nothing arrives - run
php artisan prmgtk-monitor:test. CheckPRMGTK_MONITOR_ENVIRONMENTS(defaultproductiononly),min_level, the throttle window, and that the exception is not indontReport. If the exception class defines its ownreport()method returning anything butfalse, Laravel skips reportable callbacks. - 401 - the key is wrong or no longer valid; contact prmgtk for a new one. One warning per hour is written to your log:
prmgtk monitor: invalid key. - 429 - rate limited (120 requests/minute per site). Sending pauses for the
Retry-Afterperiod. config:cache- after changing.envrunphp artisan config:clear/config:cache; closures in the config file breakconfig:cache.- Queue workers - restart workers (
queue:restart) after changing config.
Uninstall
composer remove prmgtk/laravel-monitor
rm config/prmgtk-monitor.php
Remove the PRMGTK_MONITOR_* keys from .env and any prmgtk channel from config/logging.php.
Testing
composer install
vendor/bin/phpunit
# optional end-to-end run against a real receiver
PRMGTK_E2E_KEY=prm_... PRMGTK_E2E_URL=http://localhost:8000 vendor/bin/phpunit --group e2e
License
MIT
العربية
ماذا تفعل الحزمة؟
ترسل أخطاء أي موقع لارافيل تلقائياً إلى منصة prmgtk لمراقبة الأخطاء، فتظهر في صندوق الأخطاء مع إشعار للفريق. تلتقط الاستثناءات غير المعالجة والأخطاء القاتلة وفشل مهام الطابور، وتحترم قائمة dontReport في تطبيقك، ولا تغيّر سلوك السجلات الاعتيادي. لا تؤثر على سرعة الموقع: الإرسال يتم بعد إرسال الاستجابة بمهلة 1.5 ثانية، وكل مسار محمي بحيث لا تكسر الحزمة موقعك أبداً.
المتطلبات
PHP 8.1 أو أحدث، ولارافيل 10 أو 11 أو 12 أو 13.
التركيب
- Packagist (بعد النشر):
composer require prmgtk/laravel-monitor - مستودع GitHub: أضف في
composer.jsonللموقع قسمrepositoriesبنوعvcsورابط المستودع، ثمcomposer require prmgtk/laravel-monitor:^1.0. - مسار محلي: أضف مستودعاً بنوع
pathيشير إلى مجلد الحزمة (انظر الأمثلة بالإنجليزية أعلاه).
ثم نفّذ:
php artisan prmgtk-monitor:install
وأضف المفتاح في .env:
PRMGTK_MONITOR_KEY=prm_xxxxxxxxxxxxxxxx
PRMGTK_MONITOR_URL=https://prmgtk.com
المفتاح السري
تستلم المفتاح السري الخاص بموقعك من إدارة برمجتك. احفظه في ملف .env فقط ولا ترفعه على Git.
الاختبار
php artisan prmgtk-monitor:test
يتحقق من الإعدادات ويختبر الاتصال ثم يرسل استثناءً تجريبياً بعنوان "prmgtk monitor test exception". يعمل حتى لو كانت البيئة الحالية غير مفعّلة (مع تنبيه، والخيار --force يخفيه).
أهم الإعدادات
PRMGTK_MONITOR_ENVIRONMENTS: البيئات التي تُرسل الأخطاء (الافتراضيproduction؛ اتركه فارغاً لكل البيئات).PRMGTK_MONITOR_THROTTLE_SECONDS: الخطأ المتطابق يُرسل مرة واحدة كل 60 ثانية لكل خادم.PRMGTK_MONITOR_MAX_PER_MINUTE: قاطع محلي (30 تقريراً في الدقيقة).PRMGTK_MONITOR_QUEUE_ENABLED: إرسال عبر الطابور بدل الإرسال المباشر.
الإرسال اليدوي
PrmgtkMonitor::captureException($e, ['order_id' => 15]);
PrmgtkMonitor::captureMessage('بطء في بوابة الدفع', 'warning');
قناة السجلات
أضف في config/logging.php: 'prmgtk' => ['driver' => 'prmgtk', 'level' => 'error'] ثم أضفها إلى قناة stack.
الخصوصية
كلمات المرور والرموز والكوكيز وبيانات البطاقات تُستبدل بـ [filtered] بشكل متكرر في الطلب والسياق. لا تُرسل ترويسات Authorization وCookie وCSRF أبداً، وتُستبدل الملفات المرفوعة بوصف نصي، ولا يُرسل من المستخدم إلا المعرّف والبريد، والمسارات نسبية لمجلد المشروع.
حل المشاكل
- لا تصل أخطاء: شغّل
php artisan prmgtk-monitor:test، وتأكد من البيئة (productionافتراضياً) والمستوى الأدنى، ومن أن الإعدادات غير مخزّنة قديمة (php artisan config:clear). - 401: المفتاح خاطئ أو أُعيد إنشاؤه؛ يُكتب تحذير واحد في السجل كل ساعة.
- 429: تجاوز حد المعدل؛ يتوقف الإرسال تلقائياً للمدة المطلوبة.
إلغاء التركيب
composer remove prmgtk/laravel-monitor
ثم احذف ملف config/prmgtk-monitor.php ومفاتيح PRMGTK_MONITOR_* من .env.