2014-03-21 04:51:45 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
|
|
|
|
|
2015-03-23 00:53:24 +00:00
|
|
|
namespace MediaWiki\Logger\Monolog;
|
|
|
|
|
|
2014-03-21 04:51:45 +00:00
|
|
|
/**
|
Provide a unique request identifier
When MediaWiki encounters an unhandled exception, the error message it produces
includes a randomly-generated token, which allows the exception details to be
looked up in the error logs. This is useful but narrow: would it not be useful
to have the ability to retrieve all log records associated with a particular
request, rather than just exception details? (Hint: yes.)
So: introduce the notion of a request-global unique ID, retrievable via
WebRequest::getRequestId(). When MediaWiki is behind Apache + mod_unique_id
(which provides the same facility) or some other software which sets a
UNIQUE_ID envvar, the value of that envvar is used as the request ID.
Otherwise, it is a randomly-generated 24-character string.
The request ID supplants exception-specific IDs; MWExceptionHandler::getLogId()
is deprecated, accordingly. The request ID is also added as an annotation to
all Monolog-processed log records, and is exposed client-side as 'wgRequestId'.
This allows developers to associate a page view with log records even when the
page view does not result in an unhandled exception. (For the WMF, I also
intend to add it as an annotation to profiling data).
The request ID is not a tracking token; it does not persist, and it is
associated with a backend request, not with a particular user or a particular
session. Like the data in the NewPP report, the request ID is designed to be
cacheable, so that if, for example, a developer notices something weird in the
HTML, s/he can associate the output with a backend request regardless of
whether the response was served from the cache or directly from the backend.
Some prior art:
* https://httpd.apache.org/docs/2.4/mod/mod_unique_id.html
* http://api.rubyonrails.org/classes/ActionDispatch/RequestId.html
* https://github.com/dabapps/django-log-request-id
* https://packagist.org/packages/php-middleware/request-id
* https://github.com/rhyselsmore/flask-request-id
Change-Id: Iaf90c20c330e0470b9b98627a0228cadefd301d1
2016-03-25 01:43:23 +00:00
|
|
|
* Annotate log records with request-global metadata, such as the hostname,
|
|
|
|
|
* wiki / request ID, and MediaWiki version.
|
2014-03-21 04:51:45 +00:00
|
|
|
*
|
|
|
|
|
* @since 1.25
|
2017-06-13 16:51:53 +00:00
|
|
|
* @copyright © 2013 Wikimedia Foundation and contributors
|
2014-03-21 04:51:45 +00:00
|
|
|
*/
|
2015-03-23 00:53:24 +00:00
|
|
|
class WikiProcessor {
|
2014-03-21 04:51:45 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $record
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function __invoke( array $record ) {
|
2016-02-07 21:04:55 +00:00
|
|
|
global $wgVersion;
|
2014-03-21 04:51:45 +00:00
|
|
|
$record['extra'] = array_merge(
|
|
|
|
|
$record['extra'],
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2014-03-21 04:51:45 +00:00
|
|
|
'host' => wfHostname(),
|
|
|
|
|
'wiki' => wfWikiID(),
|
2016-02-07 21:04:55 +00:00
|
|
|
'mwversion' => $wgVersion,
|
2016-03-25 16:38:16 +00:00
|
|
|
'reqId' => \WebRequest::getRequestId(),
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
2014-03-21 04:51:45 +00:00
|
|
|
);
|
|
|
|
|
return $record;
|
|
|
|
|
}
|
2016-11-23 01:01:07 +00:00
|
|
|
|
2014-03-21 04:51:45 +00:00
|
|
|
}
|