fido / php-xray
AWS X-Ray 的 PHP 仪器库
0.2.2
2023-07-07 13:48 UTC
Requires
- php: >=8.0.0
- ext-json: *
- ext-sockets: *
- webmozart/assert: ^1.11
Requires (Dev)
- guzzlehttp/guzzle: ^7.0.0
- infection/infection: ^0.25.0 || ^0.26.0
- phpstan/extension-installer: ^1.0.0
- phpstan/phpstan: 1.10.*
- phpstan/phpstan-deprecation-rules: ^1.0.0
- phpstan/phpstan-php-parser: ^1.0.0
- phpstan/phpstan-phpunit: ^1.0.0
- phpstan/phpstan-webmozart-assert: ^1.0.0
- phpunit/phpunit: ^9.0.0
- psr/http-message: ^2.0.0
- slevomat/coding-standard: ^6.0.0 || ^8.0.0
- squizlabs/php_codesniffer: ^3.0.0
This package is auto-updated.
Last update: 2024-09-18 08:04:46 UTC
README
AWS X-Ray 的 PHP 8.x 仪器库 授权 变更日志
安装
要使用此包,请使用 Composer
- 从 CLI:
composer require fido-id/php-xray
- 或者,直接在您的
composer.json
{ "require": { "fido/php-xray": "^0.2.1", } }
使用
启动新的跟踪,创建新的段,添加任何所需的子段,关闭它并提交。
例如。
$client = new \GuzzleHttp\Client(); $trace = new Trace(name: 'a_new_trace'); $httpSegment = new HttpSegment( name: \uniqid("http_segment_post_500_"), url: 'ifconfig.me/ua', method: 'GET' ); $httpSegment ->closeWithPsrResponse($client->get('ifconfig.me/ua')) $trace->addSubsegment($httpSegment); $trace->end()->submit(new DaemonSegmentSubmitter());
在提交之前必须关闭段,关闭父段将自动关闭任何子段。
可用的内置段
Segment
: 默认简单段,可由此列表中的任何其他段扩展。RemoteSegment
: 具有布尔属性$traced
的段,可由其他段扩展。DynamoSegment
: 专为 Dynamo 操作而设计的段,具有$tableName
、$operation
和$requestId
等与 Dynamo 相关的属性。HttpSegment
: 专为操作 HTTP 而设计的段,具有与$url
、$method
和$responseCode
相关的属性。它还提供了一个closeWithPsrResponse
辅助方法,允许使用实现Psr\Http\Message\ResponseInterface
接口的对象填充和关闭段。SqlSegment
: 专为 SQL 操作而设计的段,具有$query
属性和可选属性$url
、$preparation
、$databaseType
、$databaseVersion
、$driverVersion
和$user
。
您可能希望扩展上述类之一,以针对 元数据、注释 和 AWS 数据 执行自定义处理(请记住相应地扩展
__construct
和jsonSerialize
方法)。
故障和错误处理
任何段都有布尔属性 $fault
和 $error
,可以根据需要进行设置,您还可以使用 Cause
对象设置原因。
例如。
$trace = new Trace(name: 'a_new_trace'); $pdo = new \PDO('a_totally_valid_dsn'); $query = "SELECT * FROM table_name"; $sqlSegment = new SqlSegment( name: \uniqid("subsegment_sql_"), query: $query ); try { $pdo->exec($query); } catch (\Throwable $exception) { $sqlSegment->setError(true); $sqlSegment->setCause(Cause::fromThrowable($exception)); } $trace->addSubsegment($sqlSegment); $trace->end()->submit(new DaemonSegmentSubmitter());
如何测试软件
您可以通过运行 composer test
脚本来使用 PHPUnit 运行库测试套件,您还可以运行 composer mutation
脚本以获取变异测试报告。
已知问题
- 段目前仅支持
Cause
对象,但不支持异常 ID
。 - 尚未支持提交开放段。
获取帮助
如果您有任何问题、疑虑、错误报告等,请在此存储库的问题跟踪器中提交问题。
参与其中
欢迎反馈和拉取请求,有关如何贡献的更多信息,请参阅 CONTRIBUTING。
致谢和参考
此库受到 patrickkerrigan/php-xray 的启发,我们最初打算将其分叉,但最终从头开始使用 PHP8 命名构造函数重写,而不是使用流畅方法,这使得我们始终可以实例化有效的实体。