magento-lts icon indicating copy to clipboard operation
magento-lts copied to clipboard

Exception noise from OAuth and REST (API2 )

Open kiatng opened this issue 10 months ago • 5 comments

I have a project with OAuth REST which is interfacing with a mobile app. The exception.log is filling up with millions of lines due to unnecessary logs:

Mage_Api2_Exception: oauth_problem=token_rejected in .../app/code/core/Mage/Api2/Model/Auth/Adapter/Oauth.php:49 Mage_Api2_Exception: Missing required params in .../app/code/core/Mage/Api2/Model/Resource.php:629 Mage_Oauth_Exception in .../app/Mage.php:648, .../app/code/core/Mage/Oauth/Model/Server.php(421)

Each exception has 11 lines or more.

Preconditions (*)

Any version.

Steps to reproduce (*)

May be by unit tests?

Expected result (*)

  1. Do not Mage::logException($e) for Mage_Api2_Exception and Mage_Oauth_Exception?
  2. Only log one line per exception?

Actual result (*)

Noise in exception.log making it hard to detect the signal, problems that require attention.

kiatng avatar Jan 21 '25 03:01 kiatng

Mage_Api2_Exception: Missing required params in .../app/code/core/Mage/Api2/Model/Resource.php:629

Please post that lines. Looks like modified code. (?)

sreichel avatar Jan 21 '25 03:01 sreichel

Please post that lines. Looks like modified code. (?)

The project has lots of custom API2. When the client requests certain info but fail some validations, an exception is thrown, an example of bad request:

$this->_critical('Missing nationality', Mage_Api2_Model_Server::HTTP_BAD_REQUEST);

That stops further execution and informs the client (mobile phone) its request is bad, but I do not want to log this, it's unnecessary. But currently, $this->_critical() logs it in exception.log.

https://github.com/OpenMage/magento-lts/blob/00de7b5f4db329d16bff33ca497f288ebe369cd2/app/code/core/Mage/Api2/Model/Resource.php#L613-L626

Line ~629~ 625 is throw new Mage_Api2_Exception($message, $code); in my project.

kiatng avatar Jan 22 '25 03:01 kiatng

Line 629 is throw new Mage_Api2_Exception($message, $code); in my project.

In core thats line 625 ...

Isnt it correct to log "$this->_critical('Missing nationality'"?

sreichel avatar Jan 22 '25 04:01 sreichel

Sure, it is OK to log, but it's unnecessary to include the trace in the log.

kiatng avatar Feb 13 '25 10:02 kiatng

The exceptions are log here: https://github.com/OpenMage/magento-lts/blob/cf16ac85e2f0767f4a544c280410ac1ac3034576/app/code/core/Mage/Api2/Model/Server.php#L104-L107

What's the best way to handle it?

kiatng avatar Feb 22 '25 05:02 kiatng