-
Notifications
You must be signed in to change notification settings - Fork 0
Remove utopia-php/logger and report errors through spans #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: qa/agent-appwrite-appwrite/pr-12-13457/base
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
||
|
|
@@ -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. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
|
|
||
There was a problem hiding this comment.
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.