PHP code example of eerzho / opentelemetry-auto-class-laravel

1. Go to this page and download the library: Download eerzho/opentelemetry-auto-class-laravel 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-laravel example snippets


// config/trace.php
return [
    'namespaces' => [
        'App\\Services\\',
        'App\\Jobs\\',
        'Domain\\',
    ],
];

namespace App\Services;

use Eerzho\Instrumentation\Class\Attribute\Trace;
use Eerzho\Instrumentation\Class\Attribute\TraceMethod;
use Eerzho\Instrumentation\Class\Attribute\TraceProperties;

#[Trace]                                   // mark the class for tracing
class OrderService
{
    // span "App\Services\OrderService::pay"
    #[TraceMethod(exclude: ['card'])]   // hide "card" from the span
    public function pay(int $orderId, string $card, Address $address): void {}

    public function healthCheck(): bool {}   // no #[TraceMethod] -> not traced
}

#[TraceProperties(exclude: ['zip'])]       // expand every prop but zip
class Address
{
    public function __construct(public string $city, public string $zip) {}
}
bash
php artisan vendor:publish --tag=trace-config
bash
OTEL_PHP_DISABLED_INSTRUMENTATIONS=class