From 79a0b33b92d097e8495378b102a40cd643d9ae30 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Mon, 16 Feb 2026 18:46:55 +0530 Subject: [PATCH] Set project on queueForMails so span logs include project context The Mails worker span logs were missing project.id, project.sequence, project.region, and project.database because setProject was never called on queueForMails. This adds setProject in the shared API controller and in workers (Webhooks, Migrations) that trigger mails. Also injects project into the Mails worker action. --- app/controllers/shared/api.php | 1 + src/Appwrite/Platform/Workers/Mails.php | 4 +++- src/Appwrite/Platform/Workers/Migrations.php | 1 + src/Appwrite/Platform/Workers/Webhooks.php | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index f25f9717ed..378c5d5c9c 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -496,6 +496,7 @@ Http::init() $queueForMessaging->setProject($project); $queueForFunctions->setProject($project); $queueForBuilds->setProject($project); + $queueForMails->setProject($project); /* Auto-set platforms */ $queueForFunctions->setPlatform($platform); diff --git a/src/Appwrite/Platform/Workers/Mails.php b/src/Appwrite/Platform/Workers/Mails.php index b1f17fc648..72f7cddd06 100644 --- a/src/Appwrite/Platform/Workers/Mails.php +++ b/src/Appwrite/Platform/Workers/Mails.php @@ -6,6 +6,7 @@ use Appwrite\Template\Template; use Exception; use PHPMailer\PHPMailer\PHPMailer; use Swoole\Runtime; +use Utopia\Database\Document; use Utopia\Logger\Log; use Utopia\Platform\Action; use Utopia\Queue\Message; @@ -32,6 +33,7 @@ class Mails extends Action $this ->desc('Mails worker') ->inject('message') + ->inject('project') ->inject('register') ->inject('log') ->callback($this->action(...)); @@ -53,7 +55,7 @@ class Mails extends Action * @return void * @throws Exception */ - public function action(Message $message, Registry $register, Log $log): void + public function action(Message $message, Document $project, Registry $register, Log $log): void { Runtime::setHookFlags(SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_TCP); $payload = $message->getPayload() ?? []; diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index c6b005c334..94cbcf341c 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -735,6 +735,7 @@ class Migrations extends Action ]; $queueForMails + ->setProject($project) ->setSubject($subject) ->setPreview($preview) ->setBody($emailBody) diff --git a/src/Appwrite/Platform/Workers/Webhooks.php b/src/Appwrite/Platform/Workers/Webhooks.php index dbfbe591a6..56839058de 100644 --- a/src/Appwrite/Platform/Workers/Webhooks.php +++ b/src/Appwrite/Platform/Workers/Webhooks.php @@ -253,6 +253,7 @@ class Webhooks extends Action ->setParam('{{year}}', date("Y")); $queueForMails + ->setProject($project) ->setSubject($subject) ->setPreview($preview) ->setBody($body->render());