From c2d84ee25e4eb04f6c11b27c26c489ffee35af5f Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Sun, 21 Jun 2026 00:04:02 +0100 Subject: [PATCH] fix(audits): use span attributes instead of per-message Console logging The Audits worker logged on every message via Console (info/log/success/error), flooding worker logs in a hot path (thousands/s) with little signal. Replace with span telemetry on the batch flush: - drop "Aggregating audit logs" (logged per message, before the batch check) - on flush, add audits.projects and audits.count (events) to the span - on a per-project failure, add audits.error instead of Console::error Also fix a PHP 8.x deprecation: the project sequence was used directly as an array key, warning "Using null as an array offset is deprecated" when null. Cast to string (null -> "") to keep the prior coercion without the warning. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/Appwrite/Platform/Workers/Audits.php | 26 +++++++++++++----------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Audits.php b/src/Appwrite/Platform/Workers/Audits.php index e0f50756cb..6c45aa63f3 100644 --- a/src/Appwrite/Platform/Workers/Audits.php +++ b/src/Appwrite/Platform/Workers/Audits.php @@ -5,11 +5,11 @@ namespace Appwrite\Platform\Workers; use Appwrite\Event\Message\Audit; use Exception; use Throwable; -use Utopia\Console; use Utopia\Database\Document; use Utopia\Database\Exception\Structure; use Utopia\Platform\Action; use Utopia\Queue\Message; +use Utopia\Span\Span; use Utopia\System\System; class Audits extends Action @@ -63,8 +63,6 @@ class Audits extends Action $auditMessage = Audit::fromArray($payload); - Console::info('Aggregating audit logs'); - $event = $auditMessage->event; $auditPayload = ''; @@ -123,10 +121,11 @@ class Audits extends Action ]; } - if (isset($this->logs[$auditMessage->project->getSequence()])) { - $this->logs[$auditMessage->project->getSequence()]['logs'][] = $eventData; + $projectSequence = (string) $auditMessage->project->getSequence(); + if (isset($this->logs[$projectSequence])) { + $this->logs[$projectSequence]['logs'][] = $eventData; } else { - $this->logs[$auditMessage->project->getSequence()] = [ + $this->logs[$projectSequence] = [ 'project' => new Document([ '$id' => $auditMessage->project->getId(), '$sequence' => $auditMessage->project->getSequence(), @@ -148,22 +147,25 @@ class Audits extends Action return; } + $projects = 0; + $events = 0; foreach ($this->logs as $sequence => $projectLogs) { try { - Console::log('Processing Project "' . $sequence . '" batch with ' . count($projectLogs['logs']) . ' events'); - - $projectDocument = $projectLogs['project']; - $audit = $getAudit($projectDocument); + $audit = $getAudit($projectLogs['project']); $audit->logBatch($projectLogs['logs']); - Console::success('Audit logs processed successfully'); + $projects++; + $events += count($projectLogs['logs']); } catch (Throwable $e) { - Console::error('Error processing audit logs for Project "' . $sequence . '": ' . $e->getMessage()); + Span::add('audits.error', $e->getMessage()); } finally { unset($this->logs[$sequence]); } } + Span::add('audits.projects', $projects); + Span::add('audits.count', $events); + $this->lastTriggeredTime = time(); } }