PHP code example of jaigateway / monitor

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

    

jaigateway / monitor example snippets




\Insight\Insight::init(['api_key' => 'YOUR_WRITE_KEY', 'host' => 'https://monitor.jaigateway.com', 'release' => '[email protected]']);
\Insight\Insight::registerErrorHandlers();   // uncaught exceptions, fatals, warnings as breadcrumbs

try { risky(); } catch (Throwable $e) { \Insight\Insight::captureException($e); }

->withExceptions(function (Illuminate\Foundation\Configuration\Exceptions $exceptions) {
    \Insight\Laravel\Integration::handles($exceptions);
})

public function register(): void
{
    $this->reportable(function (Throwable $e) {
        \Insight\Laravel\Integration::report($e);
    });
}

$span = Insight::startSpan('payment.capture', 'stripe capture');
try { /* work */ $span->finish(true); } catch (Throwable $e) { $span->finish(false); throw $e; }

$rows = Insight::span('report.build', 'monthly report', fn () => build());   // rethrows, marks errors
Insight::recordSpan('cache', 'get', 0.4, true, ['cache.hit' => true]);       // for instrumentations

$pdo = new \Insight\Tracing\TracedPdo($dsn, $user, $pass, $options);   // query(), exec(), prepare()->execute() become spans

$stack = \GuzzleHttp\HandlerStack::create();
$stack->push(\Insight\Tracing\GuzzleMiddleware::create(), 'insight');   // Guzzle is not 

\Insight\Insight::continueTrace($payload['traceparent']);   // false for an invalid header, never throws

Insight::init([..., 'trace_propagation_targets' => ['api.example.com', '*.internal.example.com', 'localhost:8000', '#^pay[0-9]+\.example\.net$#']]);

try { return $next($request); }
catch (Throwable $e) { \Insight\Insight::captureException($e, ['request' => [
    'url' => (string) $request->getUri(), 'method' => $request->getMethod(),
]]); throw $e; }

\Insight\Insight::monitor('https://insight.yourcompany.com/api/ping/<token>/', function () { runJob(); });
\Insight\Insight::checkIn($url, 'log', 'processed 120 rows');   // 'success' | 'start' | 'fail' | 'log'