streply/streply-php

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

A Streply PHP SDK

0.0.44 2023-10-25 05:33 UTC

README

Install

composer require streply/streply-php

Initialization

Initialize Streply on beginning your code and close the connection after your code.
Both functions are mandatory for correctly working.

<?php

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

// Your code here

Streply\Flush();

Where:

  • clientPublicKey your public API key
  • projectId your project ID

Initialization with parameters

<?php

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

Filter events before send

<?php

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

Turn off Streply internal requests

<?php

Streply\Initialize(
    'https://clientPublicKey@api.streply.com/projectId',
    [
        'internalRequests' => false
    ]
);

Capture

Exception

<?php

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

Exception with params and capture level

<?php

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

Activity

<?php

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

Log

<?php

Streply\Log(
    'log.name', 
    [
        'paramName' => 'paramValue'
    ],
    '#optionalChannel',
    Level::CRITICAL 
);

Capture levels

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

Breadcrumbs

<?php

use Streply\Enum\BreadcrumbType;

Streply\Activity('someActivity');

Streply\Breadcrumb(BreadcrumbType::INFO, 'firstBreadcrumb for someActivity');
Streply\Breadcrumb(BreadcrumbType::DEBUG, 'secondBreadcrumb for someActivity', [
    'parameterName' => 'parameterValue'
]);

Available types: BreadcrumbType::INFO, BreadcrumbType::DEBUG, BreadcrumbType::ERROR and BreadcrumbType::QUERY.

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'
]);

Display logs

<?php

print_r(Streply\Logs());