From 213c76c304b6f636d408b0b9e0a22d9e8af3ea69 Mon Sep 17 00:00:00 2001 From: Jose Andres Tejerina Date: Wed, 29 Oct 2025 15:20:49 -0300 Subject: [PATCH] chore: implement queue for logguer with otlp --- app/Audit/AuditLogOtlpStrategy.php | 6 ++--- app/Jobs/EmitAuditLogJob.php | 38 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 app/Jobs/EmitAuditLogJob.php diff --git a/app/Audit/AuditLogOtlpStrategy.php b/app/Audit/AuditLogOtlpStrategy.php index ee57b56f0..1cc538f41 100644 --- a/app/Audit/AuditLogOtlpStrategy.php +++ b/app/Audit/AuditLogOtlpStrategy.php @@ -16,8 +16,8 @@ use App\Audit\ConcreteFormatters\EntityCreationAuditLogFormatter; use App\Audit\ConcreteFormatters\EntityDeletionAuditLogFormatter; use App\Audit\ConcreteFormatters\EntityUpdateAuditLogFormatter; -use Keepsuit\LaravelOpenTelemetry\Facades\Logger; use Illuminate\Support\Facades\Log; +use App\Jobs\EmitAuditLogJob; /** * OpenTelemetry Logs Audit Strategy */ @@ -114,11 +114,11 @@ public function audit($subject, array $change_set, string $event_type): void $auditData['audit.description'] = $description; } Log::debug("AuditLogOtlpStrategy::audit sending entry to OTEL", ["user_id" => $user_id, "user_email" => $user_email]); - Logger::info($this->getLogMessage($event_type), $auditData); + EmitAuditLogJob::dispatch($this->getLogMessage($event_type), $auditData); Log::debug("AuditLogOtlpStrategy::audit entry sent to OTEL", ["user_id" => $user_id, "user_email" => $user_email]); } catch (\Exception $ex) { - Logger::warning('OTEL audit logging error: ' . $ex->getMessage(), [ + Log::error('OTEL audit logging error: ' . $ex->getMessage(), [ 'exception' => $ex, 'subject_class' => get_class($subject), 'event_type' => $event_type, diff --git a/app/Jobs/EmitAuditLogJob.php b/app/Jobs/EmitAuditLogJob.php new file mode 100644 index 000000000..5c14ef0f1 --- /dev/null +++ b/app/Jobs/EmitAuditLogJob.php @@ -0,0 +1,38 @@ +logMessage = $logMessage; + $this->auditData = $auditData; + } + + public function handle(): void + { + try { + Logger::info($this->logMessage, $this->auditData); + } catch (\Exception $e) { + Log::error("EmitAuditLogJob::handle failed", [ + 'message' => $this->logMessage, + 'error' => $e->getMessage() + ]); + } + } +} \ No newline at end of file