X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiMain.php;h=680e7dcab5cef5f6e4782f88d4907bcd0acb33c7;hb=37b3383e8b5260a9674cef834d272874c0ea2589;hp=bc76f8f306f7bf225d14629644791f8f2d7f4603;hpb=2452bc3c492832c344ec123970739bbd5dcc3e65;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index bc76f8f306..680e7dcab5 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -829,6 +829,7 @@ class ApiMain extends ApiBase { 'dnt', 'origin', /* MediaWiki whitelist */ + 'user-agent', 'api-user-agent', ] ); foreach ( $requestedHeaders as $rHeader ) { @@ -1276,8 +1277,8 @@ class ApiMain extends ApiBase { if ( $lagInfo['lag'] > $maxLag ) { $response = $this->getRequest()->response(); - $response->header( 'Retry-After: ' . max( intval( $maxLag ), 5 ) ); - $response->header( 'X-Database-Lag: ' . intval( $lagInfo['lag'] ) ); + $response->header( 'Retry-After: ' . max( (int)$maxLag, 5 ) ); + $response->header( 'X-Database-Lag: ' . (int)$lagInfo['lag'] ); if ( $this->getConfig()->get( 'ShowHostnames' ) ) { $this->dieWithError( @@ -1591,17 +1592,14 @@ class ApiMain extends ApiBase { $this->setupExternalResponse( $module, $params ); } - // Execute $module->execute(); Hooks::run( 'APIAfterExecute', [ &$module ] ); $this->reportUnusedParams(); if ( !$this->mInternalMode ) { - // append Debug information MWDebug::appendDebugInfoToApiResult( $this->getContext(), $this->getResult() ); - // Print result data $this->printResult(); } } @@ -1631,7 +1629,7 @@ class ApiMain extends ApiBase { */ protected function logRequest( $time, $e = null ) { $request = $this->getRequest(); - $logCtx = [ + $legacyLogCtx = [ 'ts' => time(), 'ip' => $request->getIP(), 'userAgent' => $this->getUserAgent(), @@ -1642,17 +1640,43 @@ class ApiMain extends ApiBase { 'params' => [], ]; + $logCtx = [ + '$schema' => '/mediawiki/api/request/0.0.1', + 'meta' => [ + 'id' => UIDGenerator::newUUIDv1(), + 'dt' => gmdate( 'c' ), + 'domain' => $this->getConfig()->get( 'ServerName' ), + 'stream' => 'mediawiki.api-request' + ], + 'http' => [ + 'method' => $request->getMethod(), + 'client_ip' => $request->getIP(), + 'request_headers' => [ + 'user-agent' => $request->getHeader( 'User-agent' ), + 'api-user-agent' => $request->getHeader( 'Api-user-agent' ) + ], + ], + 'database' => wfWikiID(), + 'backend_time_ms' => (int)round( $time * 1000 ), + 'params' => [] + ]; + + $logCtx['meta']['request_id'] = + $logCtx['http']['request_headers']['x-request-id'] = WebRequest::getRequestId(); + if ( $e ) { + $logCtx['api_error_codes'] = []; foreach ( $this->errorMessagesFromException( $e ) as $msg ) { - $logCtx['errorCodes'][] = $msg->getApiCode(); + $legacyLogCtx['errorCodes'][] = $msg->getApiCode(); + $logCtx['api_error_codes'][] = $msg->getApiCode(); } } // Construct space separated message for 'api' log channel $msg = "API {$request->getMethod()} " . wfUrlencode( str_replace( ' ', '_', $this->getUser()->getName() ) ) . - " {$logCtx['ip']} " . - "T={$logCtx['timeSpentBackend']}ms"; + " {$legacyLogCtx['ip']} " . + "T={$legacyLogCtx['timeSpentBackend']}ms"; $sensitive = array_flip( $this->getSensitiveParams() ); foreach ( $this->getParamsUsed() as $name ) { @@ -1671,13 +1695,17 @@ class ApiMain extends ApiBase { $encValue = $this->encodeRequestLogValue( $value ); } + $legacyLogCtx['params'][$name] = $value; $logCtx['params'][$name] = $value; $msg .= " {$name}={$encValue}"; } wfDebugLog( 'api', $msg, 'private' ); - // ApiAction channel is for structured data consumers - wfDebugLog( 'ApiAction', '', 'private', $logCtx ); + // ApiAction channel is for structured data consumers. + // The ApiAction was using logging channel is deprecated and is replaced + // by the api-request channel. + wfDebugLog( 'ApiAction', '', 'private', $legacyLogCtx ); + wfDebugLog( 'api-request', '', 'private', $logCtx ); } /**