diff --git a/core/lib/Drupal/Core/Database/Log.php b/core/lib/Drupal/Core/Database/Log.php
index 14f5a38..9f26fab 100644
--- a/core/lib/Drupal/Core/Database/Log.php
+++ b/core/lib/Drupal/Core/Database/Log.php
@@ -120,7 +120,7 @@ public function log(StatementInterface $statement, $args, $time) {
         'query' => $statement->getQueryString(),
         'args' => $args,
         'target' => $statement->dbh->getTarget(),
-        'caller' => $this->findCaller(),
+        'caller' => $this->findCaller(debug_backtrace()),
         'time' => $time,
       );
     }
@@ -144,8 +144,7 @@ public function log(StatementInterface $statement, $args, $time) {
    *   called into the database system, not the function and args of the
    *   database call itself.
    */
-  public function findCaller() {
-    $stack = debug_backtrace();
+  public function findCaller($stack) {
     for ($i = 0, $stack_count = count($stack); $i < $stack_count; ++$i) {
       // If the call was made from a function, 'class' will be empty. It's
       // just easier to give it a default value than to try and integrate
@@ -153,7 +152,10 @@ public function findCaller() {
       if (empty($stack[$i]['class'])) {
         $stack[$i]['class'] = '';
       }
-      if (strpos($stack[$i]['class'], __NAMESPACE__) === FALSE && strpos($stack[$i + 1]['function'], 'db_') === FALSE && !empty($stack[$i]['file'])) {
+      if (strpos($stack[$i]['class'], __NAMESPACE__) === FALSE &&
+          strpos($stack[$i]['class'], 'Drupal\Driver\Database') === FALSE &&
+          strpos($stack[$i + 1]['function'], 'db_') === FALSE &&
+          !empty($stack[$i]['file'])) {
         $stack[$i] += array('file' => '?', 'line' => '?', 'args' => array());
         return array(
           'file' => $stack[$i]['file'],
