From: Tim Düsterhus Date: Sun, 5 May 2019 19:17:52 +0000 (+0200) Subject: Support adding a request ID to logged / printed exceptions X-Git-Tag: 5.2.0_Alpha_1~69^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=2c1520ae5b6f6d465af641b4cdd171a065da0736;p=GitHub%2FWoltLab%2FWCF.git Support adding a request ID to logged / printed exceptions This can be used to correlate requests in logfiles across the whole stack from reverse proxy / CDN through web server to PHP and WoltLab Suite. --- diff --git a/wcfsetup/install/files/lib/core.functions.php b/wcfsetup/install/files/lib/core.functions.php index a287a9b374..8a888d0a9e 100644 --- a/wcfsetup/install/files/lib/core.functions.php +++ b/wcfsetup/install/files/lib/core.functions.php @@ -97,6 +97,14 @@ namespace { } // @codingStandardsIgnoreStart +namespace wcf { + function getRequestId() { + if (!defined('WCF_REQUEST_ID_HEADER') || !WCF_REQUEST_ID_HEADER) return ''; + + return $_SERVER[WCF_REQUEST_ID_HEADER] ?? ''; + } +} + namespace wcf\functions\exception { use wcf\system\WCF; use wcf\system\exception\IExtraInformationException; @@ -124,7 +132,7 @@ namespace wcf\functions\exception { 'Message: '.$stripNewlines($e->getMessage())."\n". 'PHP version: '.phpversion()."\n". 'WoltLab Suite version: '.WCF_VERSION."\n". - 'Request URI: '.$stripNewlines($_SERVER['REQUEST_URI'] ?? '')."\n". + 'Request URI: '.$stripNewlines($_SERVER['REQUEST_URI'] ?? '').(\wcf\getRequestId() ? ' ('.\wcf\getRequestId().')' : '')."\n". 'Referrer: '.$stripNewlines($_SERVER['HTTP_REFERER'] ?? '')."\n". 'User Agent: '.$stripNewlines($_SERVER['HTTP_USER_AGENT'] ?? '')."\n". 'Peak Memory Usage: '.memory_get_peak_usage().'/'.FileUtil::getMemoryLimit()."\n"; @@ -178,6 +186,7 @@ namespace wcf\functions\exception { */ function printThrowable($e) { $exceptionID = logThrowable($e, $logFile); + if (\wcf\getRequestId()) $exceptionID .= '/'.\wcf\getRequestId(); $exceptionTitle = $exceptionSubtitle = $exceptionExplanation = ''; $logFile = sanitizePath($logFile);