PHP code example of elazaroo / pulse-boosted

1. Go to this page and download the library: Download elazaroo/pulse-boosted 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/ */

    

elazaroo / pulse-boosted example snippets


use App\Models\User;
use Illuminate\Support\Facades\Gate;

Gate::define('viewPulseBoosted', function (User $user) {
    return $user->isAdministrator();
});

Gate::define('managePulseBoostedQueues', function (User $user) {
    return $user->isAdministrator();
});

// config/pulse-boosted.php
'recorders' => [
    Recorders\Jobs::class => [
        'capture_payload' => env('PULSE_BOOSTED_JOBS_CAPTURE_PAYLOAD', false),
        'redact' => ['password', 'secret', 'token', 'api_key', 'authorization', /* ... */],
        'trim' => ['keep' => env('PULSE_BOOSTED_JOBS_KEEP', '7 days')],
    ],
],

// config/pulse-boosted.php
'traces' => [
    'enabled' => env('PULSE_BOOSTED_TRACES_ENABLED', true),
    'sample_rate' => env('PULSE_BOOSTED_TRACES_SAMPLE_RATE', 0.1),
    'sample_rates' => [
        'request' => 0.1,
        'job' => 0.5,
        'command' => 1.0,
        'schedule' => 1.0,
    ],
    'max_events' => 500,
    'log_level' => env('PULSE_BOOSTED_TRACES_LOG_LEVEL', 'debug'),
    'trim' => ['keep' => env('PULSE_BOOSTED_TRACES_KEEP', '24 hours')],
],

use Elazaroo\PulseBoosted\Traces\Tracer;

app(Tracer::class)->ignore(function () {
    // Nothing in here is recorded.
});

use Elazaroo\PulseBoosted\Facades\Pulse as PulseBoosted;

PulseBoosted::context([
    'tenant' => $tenant->id,
    'order' => $order->id,
    'plan' => $tenant->plan,
]);

use Elazaroo\PulseBoosted\Http\Middleware\Sample;

Route::post('/checkout', CheckoutController::class)->middleware(Sample::always());
Route::get('/health', HealthController::class)->middleware(Sample::never());
Route::get('/search', SearchController::class)->middleware(Sample::rate(0.01));

PulseBoosted::rejectQueries(fn (string $sql) => str_contains($sql, 'telescope_'));
PulseBoosted::rejectCacheKeys(['/^rate-limit:/']);
PulseBoosted::rejectOutgoingRequests(fn (string $url) => str_contains($url, 'metrics.internal'));
PulseBoosted::redactOutgoingRequests(fn (string $url) => preg_replace('/token=[^&]+/', 'token=***', $url));

// Or any kind of event: query, cache, http, log, mail, notification, job.
PulseBoosted::rejectTraceEvents('log', fn (string $message) => str_starts_with($message, 'Heartbeat'));
PulseBoosted::redactTraceEvents('log', fn (string $message) => preg_replace('/\d{16}/', '****', $message));

// config/pulse-boosted.php
'alerts' => [
    'enabled' => true,
    'check_every' => '1 minute',
    'rules' => [
        [
            'name' => 'Error rate',
            'metric' => 'error_rate',
            'threshold' => 5,
            'comparison' => 'above',   // or 'below'
            'window' => '5 minutes',
            'options' => ['type' => 'request'],
            'description' => 'More than 5% of requests are failing.',
        ],
        [
            'name' => 'Default queue backing up',
            'metric' => 'queue_size',
            'threshold' => 1000,
            'options' => ['queue' => 'default'],
        ],
    ],
],

use Elazaroo\PulseBoosted\Events\AlertResolved;
use Elazaroo\PulseBoosted\Events\AlertTriggered;

Event::listen(function (AlertTriggered $event) {
    Notification::route('slack', config('alerting.slack'))
        ->notify(new SomethingIsWrong($event->rule->name, $event->value));
});

Event::listen(function (AlertResolved $event) {
    // Worth sending too: an alert nobody is told has ended is an alert
    // somebody is still worrying about.
});

// config/pulse-boosted.php
'issues' => [
    'thresholds' => [
        'request' => ['GET /checkout' => 800, '#^GET /api/#' => 300, '*' => 2000],
        'job' => ['App\Jobs\SendInvoice' => 5000],
    ],
],