PHP code example of songhieu / monitor-track-laravel

1. Go to this page and download the library: Download songhieu/monitor-track-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

songhieu / monitor-track-laravel example snippets


// config/logging.php (added for you if missing)
'monitor-track' => [
    'driver' => 'custom',
    'via' => MonitorTrack\Monolog\ChannelFactory::class,
    'level' => env('MT_LOG_LEVEL', 'debug'),
],

use MonitorTrack\Facades\MonitorTrack;

MonitorTrack::log('warning', 'Payment retry scheduled', ['order_id' => 991]);
MonitorTrack::captureException($e, ['order_id' => 991]);

// Work outside Laravel's queue / scheduler:
MonitorTrack::trackJob('imports', ImportCsv::class, fn () => $importer->run());
MonitorTrack::trackCron('reports:nightly', '0 2 * * *', fn () => $reports->build());

MonitorTrack::stats();   // ['emitted' => …, 'dropped' => …, 'sampled' => …, 'errors' => …]
MonitorTrack::flush();   // http transport: send the buffer now (2 s budget)
MonitorTrack::flushIfDue(); // http transport: send if 2 s passed or 500 events wait (daemon loops)

$events = MonitorTrack::fake();
dispatch_sync(new SendInvoiceEmail($invoice));
$this->assertCount(1, $events->events('exception'));
bash
kubectl -n billing exec deploy/billing-api -- php artisan mt:test --pod-log
bash
php artisan vendor:publish --tag=monitor-track-config
text
N+1 query: 37× select * from `users` where `users`.`id` = ? limit ?      GET /orders/{order}
  app/Http/Controllers/OrderController.php:42  App\Http\Controllers\OrderController->index