PHP code example of iqlearning / laravel-otel

1. Go to this page and download the library: Download iqlearning/laravel-otel 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/ */

    

iqlearning / laravel-otel example snippets


use OpenTelemetry\API\Trace\TracerInterface;

class YourController extends Controller
{
    public function __construct(
        private TracerInterface $tracer
    ) {}

    public function yourMethod()
    {
        $span = $this->tracer
            ->spanBuilder('your.operation')
            ->startSpan();

        try {
            // Your business logic
            $result = $this->doSomething();

            $span->addEvent('operation.completed');

            return $result;
        } finally {
            $span->end();
        }
    }
}
bash
php artisan vendor:publish --provider="Iqlearning\LaravelOtel\OpenTelemetryServiceProvider"