Replace unstructured logging in screenshots worker with Span

Drop the Console::log narration and the Console::warning error dump in
the screenshots worker. Add Span::add tracing for context (project.id,
deployment.id, site.id, site.framework, screenshot.count), following the
conventions used by the Builds worker.

Error reporting is left to the worker harness: the catch block already
rethrows, and app/worker.php records the Throwable on the span via
setError, so the handler no longer duplicates it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
loks0nandClaude Opus 4.8 committed 2026-06-09 11:15:46 +01:00
1 parent c73f256bff
commit 06f9335547
1 file changed
+8 -8
@@ -10,7 +10,6 @@ use Appwrite\Role;
use Exception;
use Utopia\Compression\Compression;
use Utopia\Config\Config;
use Utopia\Console;
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Helpers\ID;
@@ -18,6 +17,7 @@ use Utopia\Database\Query;
use Utopia\Fetch\Client as FetchClient;
use Utopia\Platform\Action;
use Utopia\Queue\Message;
use Utopia\Span\Span;
use Utopia\Storage\Device;
use Utopia\System\System;
use Utopia\Telemetry\Adapter as Telemetry;
@@ -59,7 +59,7 @@ class Screenshots extends Action
Device $deviceForFiles,
Telemetry $telemetry
): void {
Console::log('Screenshot action started');
Span::add('project.id', $project->getId());
$payload = $message->getPayload();
@@ -70,9 +70,8 @@ class Screenshots extends Action
$screenshotMessage = Screenshot::fromArray($payload);
$counter = $telemetry->createCounter('worker.screenshots.capture');
Console::log('Site screenshot started');
$deploymentId = $screenshotMessage->deploymentId;
Span::add('deployment.id', $deploymentId);
$deployment = $dbForProject->getDocument('deployments', $deploymentId);
if ($deployment->isEmpty()) {
@@ -80,12 +79,15 @@ class Screenshots extends Action
}
$siteId = $deployment->getAttribute('resourceId');
Span::add('site.id', $siteId);
$site = $dbForProject->getDocument('sites', $siteId);
if ($site->isEmpty()) {
throw new \Exception('Site not found');
}
Span::add('site.framework', $site->getAttribute('framework', ''));
// Realtime preparation
$event = "sites.[siteId].deployments.[deploymentId].update";
$queueForRealtime
@@ -205,6 +207,8 @@ class Screenshots extends Action
throw new \Exception($screenshotError);
}
Span::add('screenshot.count', \count($screenshots));
$mimeType = "image/png";
$updates = new Document([]);
@@ -268,10 +272,6 @@ class Screenshots extends Action
'deploymentScreenshotLight' => $deployment->getAttribute('screenshotLight', ''),
]));
} catch (\Throwable $th) {
Console::warning("Screenshot failed to generate:");
Console::warning($th->getMessage());
Console::warning($th->getTraceAsString());
$date = \date('H:i:s');
$this->appendToLogs($dbForProject, $deployment->getId(), $queueForRealtime, "[$date] [appwrite] Screenshot capturing failed. Deployment will continue. \n");