PHP code example of streply / streply-php

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

    

streply / streply-php example snippets


Streply\Initialize('https://[email protected]/projectId');

Streply\Initialize(
    'https://[email protected]/projectId',
    [
        'release' => '[email protected]',
        'environment' => 'production',
    ]
);

try {
    if(true) {
        throw new \Exceptions\SomeException('Exception message here');
    }
} catch(\Exceptions\ParentException $exception) {
    Streply\Exception($exception);
}

use Streply\Enum\Level;

try {
    if(true) {
        throw new \Exceptions\SomeException('Exception message here');
    }
} catch(\Exceptions\ParentException $exception) {
    Streply\Exception(
        $exception,
        [
            'paramName' => 'paramValue'
        ],
        Level::CRITICAL
    );
}

Streply\Log('log.name', ['paramName' => 'paramValue']);

Streply\Activity('message', ['paramName' => 'paramValue']);

Streply\Performance::Start('transactionId', 'Product checkout');

Streply\Performance::Point('transactionId', 'calculate price');

...

Streply\Performance::Point('transactionId', 'cart amount', [
    'amount' => 100.56
]);

Streply\Performance::Finish('transactionId');

Streply\User('[email protected]');

Streply\User('[email protected]', 'Joey Tribbiani', [
    'createdAt' => '2022-11-10 15:10:32'
]);

\Streply\setScope(function (\Streply\Scope $scope): void {
    $scope->setChannel('my-chanel');
});

\Streply\withScope(function (\Streply\Scope $scope): void {
    $scope->setChannel('my-chanel');
    
    \Streply\Log('my log with channel');
});

Streply\Initialize(
    'https://[email protected]/projectId',
    [
        'filterBeforeSend' => function(\Streply\Entity\Event $event): bool {
            if($event->getMessage() === 'someMessage') {
                return false;
            }
            
            return true;
        }
    ]
);

Streply\Configuration::filterBeforeSend(function(\Streply\Entity\Event $event) {
    if($event->getMessage() === 'someMessage') {
        return false;
    }

    return true;
});

Streply\Configuration::ignoreExceptions([
    App\Exception\QueryException::class,
    App\Exception\InvalidAuthorizationException::class,
]);

print_r(Streply\Logs());

composer