Page MenuHomePhabricator

HttpError should not be logged as an unhandled exception.
Closed, ResolvedPublic

Description

HttpError is a way to signal an issue to the client, it does not generally imply a programming error or failure on the server side (at least for status codes < 500). Thus, writing it to "the exception log" with wfDebugLog( 'exception', ... ) is misleading.

I suggest the following behavior:

  • HttpError::isLoggable should return false if $this->httpCode < 500.
  • HttpError::report should write to the web server error log (via wfLogWarning or error_log) if $this->httpCode >= 400

Alternatively, MWExceptionHandler::logException could implement a special case for HttpError, using a different log stream, i.e. "http-error" instead of the generic "exception" log. To avoid the special case in MWExceptionHandler, MWException could get a getLogStream() method that would return "exception" per default.

Event Timeline

daniel raised the priority of this task from to Needs Triage.
daniel updated the task description. (Show Details)
daniel added a project: MediaWiki-Core-Team.
daniel added subscribers: hoo, Krinkle, Addshore.
daniel subscribed.
This comment was removed by hoo.

Often 404 errors where this is used are of no interest to ops or devs, so I prefer the different log stream, at least for 404.

Change 183020 had a related patch set uploaded (by Hoo man):
Don't log HttpErrors in the exception log

https://gerrit.wikimedia.org/r/183020

Patch-For-Review

I can't figure out why currently these show up in logstash as type:HttpError instead of type:exception. Any ideas?

I can't figure out why currently these show up in logstash as type:HttpError instead of type:exception. Any ideas?

It happens from the exception-json event processing. See https://github.com/wikimedia/operations-puppet/blob/production/files/logstash/filter-mw-via-udp2log.conf#L279-L301

Thx. No wonder searching for type in that file didn't find where it was set to HttpError.

The goal is that everything that is logged can be easily differentiated according to its severity. Like fatals/errors/warnings/notices vs things that might be helpful for debugging something but are normal operation. A 404 of this case is the later case. AFAIK in Mediawiki the log group is the only thing that can be currently used for this.
To have isLoggable() return false but then have the exception log itself inside report() is more of a workaround for the lack of being able to specify the log group. How about having logGroups() in MWException which MWExceptionHandler then uses instead of isLoggable() to determine to log the exception to the normal exception channel?

The goal is that everything that is logged can be easily differentiated according to its severity. Like fatals/errors/warnings/notices vs things that might be helpful for debugging something but are normal operation. A 404 of this case is the later case. AFAIK in Mediawiki the log group is the only thing that can be currently used for this.

Actually, we now have structured logging in MW: MWLogger::getInstance('HttpError') will return an instance of Psr\Log\LoggerInterface that you can use. You can also set a minimum log severity level in $wgDebugLogGroups (unsure if that has been deployed yet though).

The goal is that everything that is logged can be easily differentiated according to its severity. Like fatals/errors/warnings/notices vs things that might be helpful for debugging something but are normal operation. A 404 of this case is the later case. AFAIK in Mediawiki the log group is the only thing that can be currently used for this.

Actually, we now have structured logging in MW: MWLogger::getInstance('HttpError') will return an instance of Psr\Log\LoggerInterface that you can use. You can also set a minimum log severity level in $wgDebugLogGroups (unsure if that has been deployed yet though).

The severity filter stuff will hit group0 today. \o/ No config updates have been done to use it yet.

Change 197503 had a related patch set uploaded (by Hoo man):
Log HttpErrors with a 500 code

https://gerrit.wikimedia.org/r/197503

Change 197503 merged by Legoktm:
Log HttpErrors with a 500 code

https://gerrit.wikimedia.org/r/197503

Change 183020 merged by jenkins-bot:
Don't log HttpErrors in the exception log, use MWLogger

https://gerrit.wikimedia.org/r/183020

hoo claimed this task.