PHP code example of vortos / vortos-tracing

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

    

vortos / vortos-tracing example snippets


use Vortos\Tracing\Config\TracingAdapter;
use Vortos\Tracing\Config\TracingSampler;
use Vortos\Tracing\DependencyInjection\VortosTracingConfig;

return static function (VortosTracingConfig $config): void {
    $config
        ->adapter(TracingAdapter::OpenTelemetry)
        ->service(
            name: $_ENV['OTEL_SERVICE_NAME'] ?? $_ENV['APP_NAME'] ?? 'checkout-api',
            version: $_ENV['APP_VERSION'] ?? '',
            environment: $_ENV['APP_ENV'] ?? 'prod',
        )
        ->otlp(
            endpoint: $_ENV['OTEL_EXPORTER_OTLP_TRACES_ENDPOINT'] ?? 'http://otel-collector:4318/v1/traces',
            headers: [],
            timeoutMs: 2000,
        )
        ->sampler(TracingSampler::Ratio, rate: 0.1)
        ->trustRemoteContext(false);
};

use Vortos\Tracing\Attribute\DisableTracing;
use Vortos\Tracing\Attribute\TraceWith;

#[TraceWith(spanName: 'checkout.place_order', sampleRate: 1.0)]
public function checkout(): Response
{
    // ...
}

#[DisableTracing]
public function health(): Response
{
    // ...
}

$tracer->setBaggageItem('tenant.id', $tenantId);