align it with cloud pattern

This commit is contained in:
harsh mahajan 2026-04-16 15:22:45 +05:30
parent 682a56c03c
commit 93b9500a95

View file

@ -21,6 +21,7 @@ use Utopia\Queue\Message;
use Utopia\Storage\Device;
use Utopia\System\System;
use Utopia\Telemetry\Adapter as Telemetry;
use Utopia\Telemetry\Counter;
use function Swoole\Coroutine\batch;
@ -67,6 +68,7 @@ class Screenshots extends Action
}
$screenshotMessage = Screenshot::fromArray($payload);
$counter = $telemetry->createCounter('worker.screenshots.capture');
Console::log('Site screenshot started');
@ -271,23 +273,21 @@ class Screenshots extends Action
$date = \date('H:i:s');
$this->appendToLogs($dbForProject, $deployment->getId(), $queueForRealtime, "[$date] [appwrite] Screenshot capturing failed. Deployment will continue. \n");
$this->recordTelemetry($telemetry, 'failure');
$this->recordTelemetry($counter, 'failure');
throw $th;
}
$this->recordTelemetry($telemetry, 'success');
$this->recordTelemetry($counter, 'success');
}
protected function recordTelemetry(Telemetry $telemetry, string $result): void
protected function recordTelemetry(Counter $counter, string $result): void
{
try {
$telemetry
->createCounter('worker.screenshots.capture')
->add(1, [
'resourceType' => RESOURCE_TYPE_SITES,
'result' => $result,
]);
$counter->add(1, [
'resourceType' => RESOURCE_TYPE_SITES,
'result' => $result,
]);
} catch (\Throwable) {
// Telemetry should never affect screenshot processing.
}