a1comms/opencensus
最新稳定版本:v8.0.1
Composer 安装命令:
composer require a1comms/opencensus
包简介
OpenCensus Trace Client for PHP
README 文档
README
Census for PHP. Census provides a framework to measure a server's resource usage and collect performance stats. This repository contains PHP related utilities and supporting software needed by Census.
Installation & basic usage
-
Install the
opencensus/opencensuspackage using composer:$ composer require opencensus/opencensus:~0.2IMPORTANT: Please ensure your version is >= 0.2.0. There is a potential security vulnerability in < 0.2.0.
-
[Optional]: Install the
opencensusextension from PECL:$ pecl install opencensus-alpha
Enable the extension in your
php.ini:extension=opencensus.so -
Initialize a tracer for your application:
use OpenCensus\Trace\Tracer; use OpenCensus\Trace\Exporter\EchoExporter; Tracer::start(new EchoExporter());
Usage
To add tracing to a block of code, you can use the closure/callable form or explicitly open and close spans yourself.
Closure/Callable (preferred)
$pi = Tracer::inSpan(['name' => 'expensive-operation'], function() { // some expensive operation return calculatePi(1000); }); $pi = Tracer::inSpan(['name' => 'expensive-operation'], 'calculatePi', [1000]);
Explicit Span Management
// Creates a detached span $span = Tracer::startSpan(['name' => 'expensive-operation']); // Opens a scope that attaches the span to the current context $scope = Tracer::withSpan($span); try { $pi = calculatePi(1000); } finally { // Closes the scope (ends the span) $scope->close(); }
Customization
Samplers
You can specify different samplers when initializing a tracer. The default
sampler is the AlwaysSampleSampler which will attempt to trace all requests.
The provided samplers are:
| Class | Description |
|---|---|
| NeverSampleSampler | Never trace any requests |
| AlwaysSampleSampler | Trace all requests |
| MultiSampler | Check multiple samplers |
| QpsSampler | Trace X requests per second. Requires a PSR-6 cache implementation |
| ProbabilitySampler | Trace X percent of requests. |
If you would like to provide your own sampler, create a class that implements
SamplerInterface.
Exporters
You can choose different exporters to send the collected traces to.
The provided exporters are:
| Class | Description | Dependency |
|---|---|---|
| EchoExporter | Output the collected spans to stdout | |
| FileExporter | Output JSON encoded spans to a file | |
| JaegerExporter | Report traces to Jaeger server via Thrift over UDP | opencensus/opencensus-exporter-jaeger |
| LoggerExporter | Exporter JSON encoded spans to a PSR-3 logger | |
| NullExporter | No-op | |
| OneLineEchoExporter | Output the collected spans to stdout with one-line | |
| StackdriverExporter | Report traces to Google Cloud Stackdriver Trace | opencensus/opencensus-exporter-stackdriver |
| ZipkinExporter | Report collected spans to a Zipkin server | opencensus/opencensus-exporter-zipkin |
If you would like to provide your own reporter, create a class that implements
ExporterInterface.
Versioning
This library follows Semantic Versioning.
Please note it is currently under active development. Any release versioned 0.x.y is subject to backwards incompatible changes at any time.
GA: Libraries defined at a GA quality level are stable, and will not introduce backwards-incompatible changes in any minor or patch releases. We will address issues and requests with the highest priority.
Beta: Libraries defined at a Beta quality level are expected to be mostly stable and we're working towards their release candidate. We will address issues and requests with a higher priority.
Alpha: Libraries defined at an Alpha quality level are still a work-in-progress and are more likely to get backwards-incompatible updates.
Current Status: Alpha
Contributing
Contributions to this library are always welcome and highly encouraged.
See CONTRIBUTING for more information on how to get started.
Releasing
See RELEASING for more information on releasing new versions.
License
Apache 2.0 - See LICENSE for more information.
Disclaimer
This is not an official Google product.
a1comms/opencensus 适用场景与选型建议
a1comms/opencensus 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.86k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 02 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 a1comms/opencensus 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 a1comms/opencensus 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 7.86k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2023-02-20