def check_and_send_telemetry()

in src/sfctl/telemetry.py [0:0]


def check_and_send_telemetry(args_list, invocation_ret_val, exception=None):
    """
    Check if telemetry should be sent, and if so, send the telemetry
    Telemetry should be sent only if the configuration allows for sending telemetry, and if we have
    batched enough data.

    Telemetry will be sent in the background.

    :param args_list: a list of strings, representing the command called along
        with its parameters
    :param invocation_ret_val: (int) The return value of calling invoke on the command in args_list
    :param exception: (str) the string version of the Exception object returned by invoking the
        command in args_list

    :return: None
    """

    # Only send telemetry if user has configured it to be on
    if get_telemetry_config():

        try:

            command_return_tuple = (invocation_ret_val, str(exception))

            command_without_params = []

            # Remove the parameters and keep only the command name
            # Do this by finding the first item which starts with "-"
            for segment in args_list:
                if segment.startswith('-'):
                    break
                command_without_params.append(segment)

            command_as_str = ' '.join(command_without_params)

            # If the commands_without_params is empty, this means that
            # sfctl is called. Don't record this, since it will show up as 'None' in telemetry
            if not command_without_params:
                # Do not send telemetry
                return

            batch_or_send_telemetry(command_as_str, command_return_tuple)

        except:  # pylint: disable=bare-except

            import sys
            ex = sys.exc_info()[0]

            # Allow telemetry to fail silently.

            logger.info(
                str.format('Not sending telemetry because python process due to error: {0}', ex))