def _ExtractResponseSummaryFields(document):
  """Extract logging fields from the response's suds.sax.document.Document.

  Args:
    document: A suds.sax.document.Document instance containing the parsed
      API response for a given API request.

  Returns:
    A dict mapping logging field names to their corresponding value.
  """
  headers = document.childAtPath('Envelope/Header/ResponseHeader')
  body = document.childAtPath('Envelope/Body')
  summary_fields = {}

  if headers is not None:
    summary_fields['requestId'] = headers.getChild('requestId').text
    summary_fields['responseTime'] = headers.getChild('responseTime').text

    # Extract AdWords-specific summary fields if they are present.
    # Note: We need to check if None because this will always evaluate False.
    service_name = headers.getChild('serviceName')
    if service_name is not None:
      summary_fields['serviceName'] = service_name.text

    method_name = headers.getChild('methodName')
    if method_name is not None:
      summary_fields['methodName'] = method_name.text

    operations = headers.getChild('operations')
    if operations is not None:
      summary_fields['operations'] = operations.text

  if body is not None:
    # Extract fault if it exists.
    fault = body.getChild('Fault')
    if fault is not None:
      summary_fields['isFault'] = True
      # Cap length of faultstring to 16k characters for summary.
      summary_fields['faultMessage'] = fault.getChild(
          'faultstring').text[:16000]
    else:
      summary_fields['isFault'] = False

  return summary_fields