samlitowitz/php-new-relic-event-api-client
最新稳定版本:v1.0.1
Composer 安装命令:
composer require samlitowitz/php-new-relic-event-api-client
包简介
PHP Client for the New Relic Event API
README 文档
README
Table of Contents
Introduction
This library introduces an interface and an implementation to interact with the New Relic Event API.
Interface
The interface is provided to allow drop-in replacement and composition.
interface Client { public function send(PhpNewRelic\CustomEventCollection $customEvents): PhpNewRelic\EventAPI\Http\Response; }
Implementation
The only validation done client size is to ensure the payload is below the maximum allowed size. Parsing errors will be handled by New Relic as described in the documentation.
The client defaults to using the Guzzle HTTP client with a timeout of 12 seconds, however the constructor accepts
anything which implements the Psr\Http\Client\ClientInterface interface.
Installation
composer require samlitowitz/php-new-relic-event-api-client
Usage
<?php use PhpNewRelic\CustomEvent; use PhpNewRelic\CustomEventCollection; use PhpNewRelic\EventAPI\Http\Client; use PhpNewRelic\EventAPI\Http\DomainName; use PhpNewRelic\EventAPI\Http\Exception\GZipEncodingFailedException; use PhpNewRelic\EventAPI\Http\Exception\PayloadExceedsMaximumSizeException; use PhpNewRelic\EventAPI\Http\Exception\SubmissionErrorException; define('NEW_RELIC_ACCOUNT_ID', '<YOUR-NEW-RELIC-ACCOUNT-ID>'); define('NEW_RELIC_API_KEY', '<YOUR-NEW-RELIC-API-KEY>'); // Instantiate the client $client = new Client(NEW_RELIC_ACCOUNT_ID, NEW_RELIC_API_KEY, DomainName::US); // Create custom event(s) $events = CustomEventCollection::fromArray([ CustomEvent::fromArray( 'yourCustomEventType', [ new CustomEvent\Attribute( new CustomEvent\Attribute\Name('stringAttr'), new CustomEvent\Attribute\Value\String_('string') ), new CustomEvent\Attribute( new CustomEvent\Attribute\Name('floatAttr'), new CustomEvent\Attribute\Value\Float_(2.1) ), new CustomEvent\Attribute( new CustomEvent\Attribute\Name('intAttr'), new CustomEvent\Attribute\Value\Integer(2) ), ] ), // ... ]); try { $response = $client->send($events); } catch (GZipEncodingFailedException $e) { // Handle a failure to encode here } catch (PayloadExceedsMaximumSizeException $e) { // Handle a too large payload side here } catch (SubmissionErrorException $e) { // Handle submission errors here } catch (Throwable $t) { // Handle other throws here }
References
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2022-08-13