def parse_labels(record)
      payload_labels = record.delete(@labels_key)
      return nil unless payload_labels
      unless payload_labels.is_a?(Hash)
        @log.error "Invalid value of '#{@labels_key}' in the payload: " \
                   "#{payload_labels}. Labels need to be a JSON object."
        return nil
      end

      non_string_keys = payload_labels.each_with_object([]) do |(k, v), a|
        a << k unless k.is_a?(String) && v.is_a?(String)
      end
      unless non_string_keys.empty?
        @log.error "Invalid value of '#{@labels_key}' in the payload: " \
                   "#{payload_labels}. Labels need string values for all " \
                   "keys; keys #{non_string_keys} don't."
        return nil
      end
      payload_labels
    rescue StandardError => err
      @log.error "Failed to extract '#{@labels_key}' from payload.", err
      return nil
    end
def parse_labels(record)
      payload_labels = record.delete(@labels_key)
      return nil unless payload_labels
      unless payload_labels.is_a?(Hash)
        @log.error "Invalid value of '#{@labels_key}' in the payload: " \
                   "#{payload_labels}. Labels need to be a JSON object."
        return nil
      end

      non_string_keys = payload_labels.each_with_object([]) do |(k, v), a|
        a << k unless k.is_a?(String) && v.is_a?(String)
      end
      unless non_string_keys.empty?
        @log.error "Invalid value of '#{@labels_key}' in the payload: " \
                   "#{payload_labels}. Labels need string values for all " \
                   "keys; keys #{non_string_keys} don't."
        return nil
      end
      payload_labels
    rescue StandardError => err
      @log.error "Failed to extract '#{@labels_key}' from payload.", err
      return nil
    end
Parse labels. Return nil if not set.