Skip to content
Open
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion lib/internal/Magento/Framework/Cache/InvalidateLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@ public function __construct(HttpRequest $request, Logger $logger)
*/
public function execute($invalidateInfo)
{
$this->logger->debug('cache_invalidate: ', $this->makeParams($invalidateInfo));
$context = $this->makeParams($invalidateInfo);
if (isset($invalidateInfo['tags'], $invalidateInfo['mode'])) {
if ($invalidateInfo['mode'] === 'all' && is_array($invalidateInfo['tags']) && empty($invalidateInfo['tags'])) {
// If we are sending a purge request to all cache storage capture the trace
// This is not a usual flow, and likely a bug is causing a performance issue
$context['trace'] = (new \Exception)->getTrace();
}
}
$this->logger->debug('cache_invalidate: ', $context);
Copy link
Contributor

Choose a reason for hiding this comment

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

btw, if. you pass exception to psr log based on monolog in format like $this->logger->debug('cache_invalidate: ', ['exception'=> new \Exception()]); it will add trace to message

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooh i didn't know that thanks. I've just given it a quick test like this to see

$this->logger->debug('cache_invalidate: ', ['exception'=> new \Exception()]);

and i get this log, it does the exception but without the full trace

main.DEBUG: cache_invalidate:  {"exception":"[object] (Exception(code: 0):  at /var/www/html/vendor/magento/framework/Cache/InvalidateLogger.php:54)"}

Am I missing a trick?

Copy link

Choose a reason for hiding this comment

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

Can't speak to @kandy's message, but another option is casting the exception to string. That should give the message, code, and full formatted trace. (string)(new \Exception()) (see https://www.php.net/manual/en/exception.tostring.php)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rhoerr that's decent, looks like this

public function execute($invalidateInfo)
{
    $context = $this->makeParams($invalidateInfo);
    if (isset($invalidateInfo['tags'], $invalidateInfo['mode'])) {
        if ($invalidateInfo['mode'] === 'all' && is_array($invalidateInfo['tags']) && empty($invalidateInfo['tags'])) {
            // If we are sending a purge request to all cache storage capture the trace
            // This is not a usual flow, and likely a bug is causing a performance issue
            $context['exception'] =  (string)(new \Exception('full purge of cache storage triggered'));
        }
    }
    $this->logger->debug('cache_invalidate: ', $context);
}
[2025-09-18T15:50:52.353321+00:00] main.DEBUG: cache_invalidate:  {"method":"GET","url":"http:/","invalidateInfo":{"tags":[],"mode":"all"},"exception":"Exception: full purge of cache storage triggered in /var/www/html/vendor/magento/framework/Cache/InvalidateLogger.php:51
Stack trace:
#0 /var/www/html/vendor/magento/framework/Cache/Frontend/Decorator/Logger.php(60): Magento\\Framework\\Cache\\InvalidateLogger->execute(Array)
#1 /var/www/html/vendor/magento/framework/Cache/Frontend/Decorator/Logger.php(48): Magento\\Framework\\Cache\\Frontend\\Decorator\\Logger->log(Array)
#2 /var/www/html/vendor/magento/framework/App/Cache.php(102): Magento\\Framework\\Cache\\Frontend\\Decorator\\Logger->clean()
#3 /var/www/html/vendor/magento/framework/App/Cache/Proxy.php(103): Magento\\Framework\\App\\Cache->clean(Array)
#4 /var/www/html/test.php(22): Magento\\Framework\\App\\Cache\\Proxy->clean(Array)
#5 {main}"} []

I'm happy with any approach really, so long as we get the full stack trace to work with. Can the adobe team please advise what they prefer :)

}

/**
Expand Down