From 1d27101770800696ededd6fa381abe34a2b9a0fb Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Thu, 9 Apr 2026 19:49:57 +0100 Subject: [PATCH] feat: add tracing spans for storage file preview timing and cache state Co-Authored-By: Claude Sonnet 4.6 --- app/controllers/shared/api.php | 6 ++++++ .../Storage/Http/Buckets/Files/Preview/Get.php | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 24744c501f..bf4ace6b05 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -37,6 +37,7 @@ use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Authorization\Input; use Utopia\Database\Validator\Roles; use Utopia\Http\Http; +use Utopia\Span\Span; use Utopia\System\System; use Utopia\Telemetry\Adapter as Telemetry; use Utopia\Validator\WhiteList; @@ -633,6 +634,7 @@ Http::init() $isDisabled = isset($plan['imageTransformations']) && $plan['imageTransformations'] === -1 && ! $user->isPrivileged($authorization->getRoles()); $key = $request->cacheIdentifier(); + Span::add('storage.cache.key', $key); $cacheLog = $authorization->skip(fn () => $dbForProject->getDocument('cache', $key)); $cache = new Cache( new Filesystem(APP_STORAGE_CACHE . DIRECTORY_SEPARATOR . 'app-' . $project->getId()) @@ -681,6 +683,8 @@ Http::init() if ($file->isEmpty()) { throw new Exception(Exception::STORAGE_FILE_NOT_FOUND); } + Span::add('storage.bucket_id', $bucketId); + Span::add('storage.file_id', $fileId); // Do not update transformedAt if it's a console user if (! $user->isPrivileged($authorization->getRoles())) { $transformedAt = $file->getAttribute('transformedAt', ''); @@ -708,10 +712,12 @@ Http::init() ->setContentType($cacheLog->getAttribute('mimeType')); $storageCacheOperationsCounter->add(1, ['result' => 'hit']); if (! $isImageTransformation || ! $isDisabled) { + Span::add('storage.cache.hit', true); $response->send($data); } } else { $storageCacheOperationsCounter->add(1, ['result' => 'miss']); + Span::add('storage.cache.hit', false); $response ->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate') ->addHeader('Pragma', 'no-cache') diff --git a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php index 22e55e672e..cf735410a3 100644 --- a/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php +++ b/src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/Preview/Get.php @@ -15,7 +15,6 @@ use Utopia\Compression\Algorithms\GZIP; use Utopia\Compression\Algorithms\Zstd; use Utopia\Compression\Compression; use Utopia\Config\Config; -use Utopia\Console; use Utopia\Database\Database; use Utopia\Database\DateTime; use Utopia\Database\Document; @@ -26,6 +25,7 @@ use Utopia\Http\Adapter\Swoole\Request; use Utopia\Image\Image; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; +use Utopia\Span\Span; use Utopia\Storage\Device; use Utopia\System\System; use Utopia\Validator\HexColor; @@ -269,7 +269,17 @@ class Get extends Action $totalTime = \microtime(true) - $startTime; - Console::info("File preview rendered,project=" . $project->getId() . ",bucket=" . $bucketId . ",file=" . $file->getId() . ",uri=" . $request->getURI() . ",total=" . $totalTime . ",rendering=" . $renderingTime . ",decryption=" . $decryptionTime . ",decompression=" . $decompressionTime . ",download=" . $downloadTime); + Span::add('storage.file_id', $file->getId()); + Span::add('storage.bucket_id', $bucketId); + Span::add('storage.file_size_bytes', $file->getAttribute('sizeActual')); + if (!empty($type)) { + Span::add('storage.file_extension', $type); + } + Span::add('storage.timing.download_seconds', $downloadTime); + Span::add('storage.timing.decryption_seconds', $decryptionTime); + Span::add('storage.timing.decompression_seconds', $decompressionTime); + Span::add('storage.timing.rendering_seconds', $renderingTime); + Span::add('storage.timing.total_seconds', $totalTime); $contentType = (\array_key_exists($output, $outputs)) ? $outputs[$output] : $outputs['jpg'];