/** * A hook for setting additional fields that will be sent to Logstash * * @param \WikiFactoryLoader $wikiFactoryLoader * @return bool true */ public static function onWikiFactoryExecuteComplete(\WikiFactoryLoader $wikiFactoryLoader) { global $wgRequest, $wgDBname, $wgCityId, $maintClass; $fields = []; if (!empty($wgDBname)) { $fields['db_name'] = $wgDBname; } if (!empty($wgCityId)) { $fields['city_id'] = $wgCityId; } if (isset($_SERVER['REQUEST_URI'])) { $fields['url'] = $_SERVER['REQUEST_URI']; $ip = !empty($wgRequest) ? $wgRequest->getIP() : null; if ($ip === null) { $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null; } if ($ip != null) { $fields['ip'] = $ip; } if (isset($_SERVER['REQUEST_METHOD'])) { $fields['http_method'] = $_SERVER['REQUEST_METHOD']; } if (isset($_SERVER['SERVER_NAME'])) { $fields['server'] = $_SERVER['SERVER_NAME']; } if (isset($_SERVER['HTTP_REFERER'])) { $fields['referrer'] = $_SERVER['HTTP_REFERER']; } } // add some context for maintenance scripts if (defined('RUN_MAINTENANCE_IF_MAIN')) { if (isset($_SERVER['SCRIPT_FILENAME'])) { $fields['maintenance_file'] = realpath($_SERVER['SCRIPT_FILENAME']); } if (!empty($maintClass)) { $fields['maintenance_class'] = $maintClass; } } $fields['request_id'] = RequestId::instance()->getRequestId(); WikiaLogger::instance()->pushContext($fields, WebProcessor::RECORD_TYPE_FIELDS); return true; }
function testSingleton() { $instance = RequestId::instance(); $this->assertEquals($instance->getRequestId(), $instance->getRequestId(), 'ID should be the same for the same instance'); $this->assertNotEquals((new RequestId())->getRequestId(), (new RequestId())->getRequestId(), 'ID should be different for different instances'); }