How can I debug entity queries in Drupal 8? Is there an out-of-the-box solution for printing the query of an entity query in Drupal 8?

Right now I'm using kind of a hack, adding:

-&gt;addTag('debug')


and then in a custom module:

function mymodule_query_alter($query) {
  if ($query-&gt;hasTag('debug')) {
    mymodule_query_debug($query);
  }
}


and then the debug function:

function mymodule_query_debug($query) {

  $sql = (string) $query;
  $quoted = array();
  foreach ((array) $query-&gt;arguments() as $key =&gt; $val) {
    if (is_array($val)) {
      $val = implode(', ',$val);
    }
    $quoted[$key] = \Drupal::database()-&gt;quote($val);
  }
  $sql = strtr($sql, $quoted);
  $sql = str_replace('}', '', $sql);
  $sql = str_replace('{', '', $sql);
  print_r($sql);
  die();
}
For Drupal 8, there is the Devel module and the Web Profiler module. The latter module, once enabled, installs a toolbar at the bottom of the page for users with the appropriate permissions. The database button within this toolbar takes you to a inspection page that shows all database queries executed during the last request. 

If you're able to trigger the entity query through any browser request, you should be able to inspect the list of DB queries for the specific entity query you're looking to debug.