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 created this task.Jan 5 2015, 1:45 PM
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 added a subscriber: daniel.
hoo added a comment.Jan 5 2015, 2:04 PM
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?

bd808 added a subscriber: bd808.Jan 6 2015, 5:28 PM

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?

Legoktm added a subscriber: Legoktm.Jan 7 2015, 6:09 PM

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).

bd808 added a comment.Jan 7 2015, 7:26 PM

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 closed this task as Resolved.Mar 18 2015, 7:13 PM
hoo claimed this task.
bd808 moved this task from Backlog to Done on the MediaWiki-Core-Team board.Mar 18 2015, 8:07 PM
bd808 moved this task from Done to Archive on the MediaWiki-Core-Team board.Mar 24 2015, 11:05 PM