PHP code example of replaystack / sdk

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

    

replaystack / sdk example snippets


use ReplayStack\Sdk\Config;
use ReplayStack\Sdk\ReplayStack;
use ReplayStack\Sdk\Runtime\ProcessGuards;

$client = new ReplayStack(new Config(
    apiKey: getenv('REPLAYSTACK_API_KEY'),
    serviceName: 'orders-api',
    environment: 'production',
    sampleRate: 1.0,
    maskFields: ['phoneNumber', 'ssn'],
    ignoredPaths: ['/health', '/internal/*'],
));

// Capture uncaught exceptions, fatal errors, and flush on shutdown.
ProcessGuards::install($client);

$client->addBreadcrumb('checkout started', 'http', 'info', ['orderId' => 42]);

try {
    // ...your code...
} catch (\Throwable $e) {
    $client->captureException($e, ['endpoint' => '/checkout', 'statusCode' => 500]);
    throw $e;
}

use ReplayStack\Sdk\Integrations\Laravel\Facades\ReplayStack;

ReplayStack::addBreadcrumb('querying products', 'db');
ReplayStack::captureException($e, ['endpoint' => '/products']);

return [
    ReplayStack\Sdk\Integrations\Symfony\ReplayStackBundle::class => ['all' => true],
];

use ReplayStack\Sdk\Integrations\Slim\ReplayStackMiddleware;
use ReplayStack\Sdk\Integrations\Psr15\MiddlewareOptions;

$app->add(new ReplayStackMiddleware($client, new MiddlewareOptions(
    ignoredPaths: ['/health', '/internal/*'],
)));

$client->flush();          // synchronously drain the offline queue
$client->flush(2.0);       // with a deadline
$client->close();          // stop accepting + drain