streply/streply-php

该软件包最新版本(0.0.60)没有可用的许可信息。

Streply PHP SDK

0.0.60 2024-04-26 07:21 UTC

README

安装

composer require streply/streply-php

初始化

在代码开始时初始化 Streply。

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

位置

  • clientPublicKey 你的公开API密钥
  • projectId 你的项目ID

使用参数初始化

Streply\Initialize(
    'https://clientPublicKey@api.streply.com/projectId',
    [
        'release' => 'my-project-name@2.3.12',
        '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']);

捕获级别

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

性能

创建事务

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('joey@streply.com');

或带有参数和名称

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

配置

作用域

使用 setScope 助手将为 Streply SDK 捕获的所有事件设置作用域。

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

如果您想更改单个事件的作用域,可以使用 withScope 助手。此助手不会保留所做的作用域更改。

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

作用域中可用的方法

  • setChannel
  • setFlag
  • setRelease
  • setEnvironment

在发送之前过滤事件

Streply\Initialize(
    'https://clientPublicKey@api.streply.com/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());