streply/streply-php

There is no license information available for the latest version (0.0.60) of this package.

A Streply PHP SDK

0.0.60 2024-04-26 07:21 UTC

README

Install

composer require streply/streply-php

Initialization

Initialize Streply on beginning your code.

Streply\Initialize('https://clientPublicKey@api.streply.com/projectId');

Where:

  • clientPublicKey your public API key
  • projectId your project ID

Initialization with parameters

Streply\Initialize(
    'https://clientPublicKey@api.streply.com/projectId',
    [
        'release' => 'my-project-name@2.3.12',
        'environment' => 'production',
    ]
);

Capture

Exception

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

Exception with params and capture level

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
    );
}

Log

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

Activity

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

Capture levels

  • Level::CRITICAL
  • Level::HIGH
  • Level::NORMAL
  • Level::LOW

Performance

Creating transaction

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

Adding point

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

...

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

Sending transaction

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

Adding user data

Streply\User('joey@streply.com');

or with parameters and name

Streply\User('joey@streply.com', 'Joey Tribbiani', [
    'createdAt' => '2022-11-10 15:10:32'
]);

Configuration

Scopes

The setScope helper will set up the scope for all events captured by the Streply SDK.

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

If you want to change the scope for a single event, you can use the withScope helper instead. This helper does not retain the scope changes made.

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

Available methods in scope:

  • setChannel
  • setFlag
  • setRelease
  • setEnvironment

Filter events before send

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

Additionally, you have the flexibility to modify all choices at a later time:

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

    return true;
});

Ignore Exceptions

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

Display logs

print_r(Streply\Logs());