Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/Audit/AuditLogOtlpStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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,
Expand Down
38 changes: 38 additions & 0 deletions app/Jobs/EmitAuditLogJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use Keepsuit\LaravelOpenTelemetry\Facades\Logger;

class EmitAuditLogJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

public $tries = 2;

public string $logMessage;
public array $auditData;

public function __construct(string $logMessage, array $auditData = [])
{
$this->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()
]);
}
}
}