def build_tracer(task):
    """Return a function that traces task execution, catches all exceptions
        and updates result backends with the state and the result.

        If the call was successful, it saves the result to the task result
        backends and sets the task state to `"SUCCESS"`.

        If the call rasies :exc:`~@Retry`, it extracts the original exception,
        uses that as result and sets the task state to `"RETRY"`.

        If the call results in an exception, it saves the exception as the task
        result, and sets the task state to `"FAILURE"`.
        """
