No description
- PHP 89%
- Shell 11%
|
All checks were successful
[Workflow] On Documentation Change / techdocs (push) Successful in 35s
[Workflow] On Documentation Change / Generate (push) Successful in 0s
[Workflow] On Documentation Change / Build (Zensical) + sync to Garage web (push) Successful in 15s
[Workflow] On Documentation Change / Deploy (docs site / Garage web) (push) Successful in 0s
Repo-scoped Garage key via repo-level TECHDOCS_S3_* (shadows org). The shared docs-site prefix stops receiving updates; the docs domain routes /telemetry-service to the new bucket in homelab's phase C cutover. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> |
||
|---|---|---|
| .forgejo/workflows | ||
| .github | ||
| docs/techdocs | ||
| src | ||
| tests | ||
| .gitignore | ||
| .releaserc.cjs | ||
| catalog-info.yml | ||
| CHANGELOG.md | ||
| composer.json | ||
| composer.lock | ||
| develop.sh | ||
| phpcs.xml | ||
| phpmd.xml | ||
| phpstan.neon | ||
| phpunit.xml.dist | ||
| psalm.xml | ||
| README.md | ||
| rector.php | ||
| renovate.json | ||
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);
}
];