PHP code example of changole / otel-logging

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

    

changole / otel-logging example snippets


'channels' => [
    // ...
    'otel' => [
        'driver' => 'monolog',
        'handler' => Changole\OtelLogging\Otel\OtelLogHandler::class,
    ],
    
    // Or use it in a stack
    'stack' => [
        'driver' => 'stack',
        'channels' => ['single', 'otel'],
        'ignore_exceptions' => false,
    ],
],

// Using the dedicated channel
Log::channel('otel')->info('This is a test message', ['user_id' => 123]);

// Or when using the stack (if you added 'otel' to your stack channels)
Log::info('This message will go to both file and OpenTelemetry', [
    'user_id' => 123,
]);

try {
    // Your code
} catch (\Exception $e) {
    Log::error('Error processing payment', [
        'exception' => $e,
        'payment_id' => $paymentId,
    ]);
}

Log::info('Processing order', [
    'order_id' => $order->id,
    'trace_id' => $traceId,
    'span_id' => $spanId,
]);
bash
php artisan vendor:publish --tag=otel-logging-config