webgrip/telemetry-service
最新稳定版本:1.0.4
Composer 安装命令:
composer require webgrip/telemetry-service
包简介
A simple telemetry service for PHP applications
README 文档
README
Prerequisites
- PHP 8.2
- Composer
How to use
Serviceprovider
TelemetryServiceProvider::class
Using TelemetryService to log
use \Webgrip\TelemetryService\Core\Domain\Services\TelemetryServiceInterface; class Foo { public function __construct(private TelemetryServiceInterface $telemetryService) { } public function bar() { $this->telemetryService->logger()->debug('Hello World'); $this->telemetryService->logger()->info('Hello World'); $this->telemetryService->logger()->warning('Hello World'); // ... } }
Using TelemetryService to trace
use \Webgrip\TelemetryService\Core\Domain\Services\TelemetryServiceInterface; class Foo { public function __construct(private TelemetryServiceInterface $telemetryService) { } public function bar() { $tracer = $this->telemetryService->tracer(); $span = $tracer->spanBuilder('foo')->startSpan(); $span->addEvent('bar'); $span->setAttributes(['foo' => 'bar']); $span->recordException(new \Exception('Hello World')); $span->addLink('foo', 'bar'); // ... $span->end(); } }
Using attributes
You can add the attribute 'Webgrip\TelemetryService\Core\Domain\Services\Traceable' to your class to automatically trace all methods of the class You can also use this attribute to trace a single method
#[\Webgrip\TelemetryService\Core\Domain\Attributes\Traceable] class Foo { public function bar() { // ... } #[\Webgrip\TelemetryService\Core\Domain\Attributes\Traceable] public function baz() { // ... } }
// DI configuration return [ Foo::class => function (\DI\Container $container) { $factory = $container->get(\Webgrip\TelemetryService\Infrastructure\Factories\TracedClassFactory::class) $foo = new Foo(); return $factory->create($foo); } ];
统计信息
- 总下载量: 118
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-18