/**
  * These values end up serialized into Avro which has strict typing
  * requirements. float !== int !== string.
  *
  * @param float $took Number of milliseconds the request took
  * @return array
  */
 private function buildLogContext($took)
 {
     $client = $this->connection->getClient();
     $query = $client->getLastRequest();
     $result = $client->getLastResponse();
     $params = $this->logContext;
     $this->logContext = array();
     $params += array('tookMs' => intval($took), 'source' => self::getExecutionContext(), 'executor' => self::getExecutionId(), 'identity' => self::generateIdentToken());
     if ($result) {
         $queryData = $query->getData();
         $resultData = $result->getData();
         $index = explode('/', $query->getPath());
         $params['index'] = $index[0];
         if (isset($resultData['took'])) {
             $elasticTook = $resultData['took'];
             $params['elasticTookMs'] = intval($elasticTook);
         }
         if (isset($resultData['hits']['total'])) {
             $params['hitsTotal'] = intval($resultData['hits']['total']);
         }
         if (isset($resultData['hits']['hits'])) {
             $num = count($resultData['hits']['hits']);
             $offset = isset($queryData['from']) ? $queryData['from'] : 0;
             $params['hitsReturned'] = $num;
             $params['hitsOffset'] = intval($offset);
         }
         if ($this->_isset($queryData, array('query', 'filtered', 'filter', 'terms', 'namespace'))) {
             $namespaces = $queryData['query']['filtered']['filter']['terms']['namespace'];
             $params['namespaces'] = array_map('intval', $namespaces);
         }
         if (isset($resultData['suggest']['suggest'][0]['options'][0]['text'])) {
             $params['suggestion'] = $resultData['suggest']['suggest'][0]['options'][0]['text'];
         }
     }
     if (self::$logContexts === null) {
         DeferredUpdates::addCallableUpdate(function () {
             ElasticsearchIntermediary::reportLogContexts();
         });
         self::$logContexts = array();
     }
     self::$logContexts[] = $params;
     return $params;
 }
 /**
  * Summarizes all the requests made in this process and reports
  * them along with the test they belong to.
  * Only public due to php 5.3 not having access from closures
  */
 public static function reportLogContexts()
 {
     if (!self::$logContexts) {
         return;
     }
     self::buildRequestSetLog();
     self::buildUserTestingLog();
     self::$logContexts = array();
 }