Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ _APP_GRAPHQL_MAX_COMPLEXITY=250
_APP_GRAPHQL_MAX_DEPTH=4
_APP_ASSISTANT_OPENAI_API_KEY=
_APP_LOGGING_CONFIG=
_APP_LOGGING_CONFIG_REALTIME=
_APP_LOGGING_FORMAT=pretty
_APP_MIGRATION_HOST=appwrite
_APP_MIGRATIONS_FIREBASE_CLIENT_ID=
Expand Down
52 changes: 7 additions & 45 deletions app/cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
use Utopia\Database\Database;
use Utopia\Database\Document;
use Utopia\Database\Validator\Authorization;
use Utopia\Logger\Log;
use Utopia\Platform\Service;
use Utopia\Pools\Group;
use Utopia\Registry\Registry;
use Utopia\System\System;
use Utopia\Span\Span;

use function Swoole\Coroutine\run;

Expand Down Expand Up @@ -178,57 +177,20 @@
$container->set('usage', function () {
return new UsageContext();
}, []);
$container->set('logError', function (Registry $register) {
return function (Throwable $error, string $namespace, string $action) use ($register) {
$container->set('logError', function () {
return function (Throwable $error, string $namespace, string $action) {
Console::error('[Error] Timestamp: ' . date('c', time()));
Console::error('[Error] Type: ' . get_class($error));
Console::error('[Error] Message: ' . $error->getMessage());
Console::error('[Error] File: ' . $error->getFile());
Console::error('[Error] Line: ' . $error->getLine());
Console::error('[Error] Trace: ' . $error->getTraceAsString());

$logger = $register->get('logger');

if ($logger) {
$version = System::getEnv('_APP_VERSION', 'UNKNOWN');

$log = new Log();
$log->setNamespace($namespace);
$log->setServer(System::getEnv('_APP_LOGGING_SERVICE_IDENTIFIER', \gethostname()));
$log->setVersion($version);
$log->setType(Log::TYPE_ERROR);
$log->setMessage($error->getMessage());

$log->addTag('code', $error->getCode());
$log->addTag('verboseType', get_class($error));

$log->addExtra('file', $error->getFile());
$log->addExtra('line', $error->getLine());
$log->addExtra('trace', $error->getTraceAsString());
$log->addExtra('detailedTrace', $error->getTrace());

if ($error->getPrevious() !== null) {
if ($error->getPrevious()->getMessage() != $error->getMessage()) {
$log->addExtra('previousMessage', $error->getPrevious()->getMessage());
}
$log->addExtra('previousFile', $error->getPrevious()->getFile());
$log->addExtra('previousLine', $error->getPrevious()->getLine());
}

$log->setAction($action);

$isProduction = System::getEnv('_APP_ENV', 'development') === 'production';
$log->setEnvironment($isProduction ? Log::ENVIRONMENT_PRODUCTION : Log::ENVIRONMENT_STAGING);

try {
$responseCode = $logger->addLog($log);
Console::info('Error log pushed with status code: ' . $responseCode);
} catch (Throwable $th) {
Console::error('Error pushing log: ' . $th->getMessage());
}
}
// Tasks run outside a request span; open one so the failure reaches the exporters.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipwright · CRITICAL

The CLI logError closure now calls $span->finish(error: $error) on the current span.

Impact: The CLI logError closure now calls $span->finish(error: $error) on the current span. If a task already has an active span (Span::current() is non-null), this finishes the caller's span prematurely. Any subsequent Span::add() or span operations in the task will target a finished span, and the exporter may emit a partial/incorrect trace. The comment says 'Tasks run outside a request span' but the code explicitly ha…

Suggested fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipwright · HIGH

The CLI logError closure no longer catches exceptions from the logging/export path.

Impact: The CLI logError closure no longer catches exceptions from the logging/export path. The old code wrapped $logger->addLog($log) in try/catch and logged a warning. The new code calls $span->finish(error: $error) without any try/catch. If the span exporter throws (e.g., Sentry network failure, malformed span data), the error handler itself will throw, potentially crashing the CLI task instead of just reporting th…

Suggested fix: Review the cited evidence, fix the risk if confirmed, and rerun Shipwright.

$span = Span::current() ?? Span::init($action);
$span->finish(error: $error);
};
}, ['register']);
}, []);

$container->set('bus', function (Registry $register) use ($container) {
return $register->get('bus')->setResolver(fn (string $name) => $container->get($name));
Expand Down
11 changes: 1 addition & 10 deletions app/config/variables.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,18 +403,9 @@
'question' => 'Enter an email that will be used when registering for SSL certificates',
'filter' => ''
],
[
'name' => '_APP_LOGGING_PROVIDER',
'description' => 'Deprecated since 1.6.0, use `_APP_LOGGING_CONFIG` with DSN value instead. This variable allows you to enable logging errors to 3rd party providers. This value is empty by default, set the value to one of \'sentry\', \'raygun\', \'appSignal\', \'logOwl\' to enable the logger.',
'introduction' => '0.12.0',
'default' => '',
'required' => false,
'question' => '',
'filter' => ''
],
[
'name' => '_APP_LOGGING_CONFIG',
'description' => 'This variable allows you to enable logging errors to third party providers. This value is empty by default, set a DSN value to one of the following `sentry://PROJECT_ID:SENTRY_API_KEY@SENTRY_HOST/`, , `logowl://SERVICE_TICKET@SERIVCE_HOST/` `raygun://RAYGUN_API_KEY/`, `appSignal://API_KEY/` to enable the logger.\n\nFor versions prior `1.5.6` you can use the old syntax.\n\nOld syntax: If using Sentry, this should be \'SENTRY_API_KEY;SENTRY_APP_ID\'. If using Raygun, this should be Raygun API key. If using AppSignal, this should be AppSignal API key. If using LogOwl, this should be LogOwl Service Ticket.',
'description' => 'This variable allows you to report server errors to Sentry. This value is empty by default, set a DSN value `sentry://PROJECT_ID:SENTRY_API_KEY@SENTRY_HOST/` to enable it. Errors are exported as spans, so every attribute added with `Span::add()` during the request or job is attached to the Sentry event.',
'introduction' => '0.12.0',
'default' => '',
'required' => false,
Expand Down
Loading