# File lib/phusion_passenger/analytics_logger.rb, line 224
        def new_transaction(group_name, category = :requests, union_station_key = nil)
                if !@server_address
                        return Log.new
                elsif !group_name || group_name.empty?
                        raise ArgumentError, "Group name may not be empty"
                end
                
                txn_id = (AnalyticsLogger.current_time.to_i / 60).to_s(36)
                txn_id << "-#{random_token(11)}"
                
                Lock.new(@mutex).synchronize do |lock|
                        if current_time < @next_reconnect_time
                                return Log.new
                        end
                        
                        Lock.new(@connection.mutex).synchronize do |connection_lock|
                                if !@connection.connected?
                                        begin
                                                connect
                                                connection_lock.reset(@connection.mutex)
                                        rescue SystemCallError, IOError
                                                @connection.disconnect
                                                DebugLogging.warn("Cannot connect to the logging agent at #{@server_address}; " +
                                                        "retrying in #{@reconnect_timeout} second(s).")
                                                @next_reconnect_time = current_time + @reconnect_timeout
                                                return Log.new
                                        rescue Exception => e
                                                @connection.disconnect
                                                raise e
                                        end
                                end
                                
                                begin
                                        @connection.channel.write("openTransaction",
                                                txn_id, group_name, "", category,
                                                AnalyticsLogger.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 Log.new(@connection, txn_id)
                                rescue SystemCallError, IOError
                                        @connection.disconnect
                                        DebugLogging.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 Log.new
                                rescue Exception => e
                                        @connection.disconnect
                                        raise e
                                end
                        end
                end
        end