# File lib/phusion_passenger/union_station/core.rb, line 101
        def new_transaction(group_name, category = :requests, union_station_key = "-")
                if !@server_address
                        return Transaction.new
                elsif !group_name || group_name.empty?
                        raise ArgumentError, "Group name may not be empty"
                end

                txn_id = (Core.current_time.to_i / 60).to_s(36)
                txn_id << "-#{random_token(11)}"

                Utils::Lock.new(@mutex).synchronize do |lock|
                        if current_time < @next_reconnect_time
                                return Transaction.new
                        end

                        Utils::Lock.new(@connection.mutex).synchronize do |connection_lock|
                                if !@connection.connected?
                                        begin
                                                connect
                                                connection_lock.reset(@connection.mutex)
                                        rescue SystemCallError, IOError
                                                @connection.disconnect
                                                warn("Cannot connect to the logging agent at #{@server_address}; " +
                                                        "retrying in #{@reconnect_timeout} second(s).")
                                                @next_reconnect_time = current_time + @reconnect_timeout
                                                return Transaction.new
                                        rescue Exception => e
                                                @connection.disconnect
                                                raise e
                                        end
                                end

                                begin
                                        @connection.channel.write("openTransaction",
                                                txn_id, group_name, "", category,
                                                Core.timestamp_string,
                                                union_station_key,
                                                true,
                                                true)
                                        result = @connection.channel.read
                                        if result != ["ok"]
                                                raise "Expected logging server to respond with 'ok', but got #{result.inspect} instead"
                                        end
                                        return Transaction.new(@connection, txn_id)
                                rescue SystemCallError, IOError
                                        @connection.disconnect
                                        warn("The logging agent at #{@server_address}" <<
                                                " closed the connection; will reconnect in " <<
                                                "#{@reconnect_timeout} second(s).")
                                        @next_reconnect_time = current_time + @reconnect_timeout
                                        return Transaction.new
                                rescue Exception => e
                                        @connection.disconnect
                                        raise e
                                end
                        end
                end
        end