PHP code example of eerzho / opentelemetry-auto-class
1. Go to this page and download the library: Download eerzho/opentelemetry-auto-class library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
eerzho / opentelemetry-auto-class example snippets
namespace App\Service;
class OrderService
{
public function pay(int $orderId, string $card, Address $address): string {}
public function healthCheck(): bool {}
}
class Address
{
public function __construct(public string $city, public string $zip) {}
}
use Eerzho\Instrumentation\Class\Attribute\Trace;
#[Trace] // mark the class for tracing
class OrderService
{
public function pay(int $orderId, string $card, Address $address): string {}
public function healthCheck(): bool {}
}
use Eerzho\Instrumentation\Class\Attribute\TraceMethod;
#[TraceMethod(exclude: ['card'])] // capture every arg but card
// #[TraceMethod(
use Eerzho\Instrumentation\Class\Attribute\TraceProperties;
#[TraceProperties(exclude: ['zip'])] // expand every prop but zip
// #[TraceProperties(
use Eerzho\Instrumentation\Class\AttributeScanner;
use Eerzho\Instrumentation\Class\ClassInstrumentation;
ClassInstrumentation::register(AttributeScanner::scan([OrderService::class]));
ClassInstrumentation::register([
OrderService::class => [
'pay' => [
'arguments' => ['orderId' => 0], // name => position
'return' => true,
'exception' => true,
],
'cancel' => ['arguments' => []], // trace, capture nothing
// methods not listed are not traced
],
]);
bash
OTEL_PHP_DISABLED_INSTRUMENTATIONS=class
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.