1. Go to this page and download the library: Download edwinekr/otel-elk-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/ */
use Edwinekr\OtelElkLaravel\Services\ActivityLogService;
class OrderController extends Controller
{
public function __construct(private ActivityLogService $activityLog)
{
}
public function checkout(Request $request)
{
$order = Order::create([...]);
$this->activityLog->log(
action: 'order.checkout',
entity: 'Order',
entityId: $order->id,
metadata: [
'total' => $order->total,
'items_count' => $order->items->count(),
]
);
return response()->json(['order' => $order]);
}
}
use Edwinekr\OtelElkLaravel\Traits\LogsActivity;
class Product extends Model
{
use LogsActivity;
// Model will automatically log created, updated, deleted events
}
use Edwinekr\OtelElkLaravel\Facades\Rum;
// Check if RUM is enabled
if (Rum::isEnabled()) {
// Get the full RUM configuration
$config = Rum::getConfig();
// Get the initialization script as JSON string
$initScript = Rum::getInitScript();
// Get the CDN URL
$cdnUrl = Rum::getCdnUrl();
// Render the complete script HTML
$html = Rum::renderScript();
}
use Edwinekr\OtelElkLaravel\Helpers\RumHelper;
// Get the full script HTML for custom implementations
$scriptHtml = RumHelper::renderScript();