Skip to content

Commit

Permalink
Merge pull request barryvdh#944 from zhuston/master
Browse files Browse the repository at this point in the history
Allow additional excluded paths for db backtrace
  • Loading branch information
barryvdh authored May 24, 2020
2 parents 979b4c1 + 81f988f commit 34f6b96
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions config/debugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
'db' => [
'with_params' => true, // Render SQL with the parameters substituted
'backtrace' => true, // Use a backtrace to find the origin of the query in your files.
'backtrace_exclude_paths' => [], // Paths to exclude from backtrace. (in addition to defaults)
'timeline' => false, // Add the queries to the timeline
'explain' => [ // Show EXPLAIN output on queries
'enabled' => false,
Expand Down
23 changes: 16 additions & 7 deletions src/DataCollector/QueryCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class QueryCollector extends PDOCollector
protected $explainTypes = ['SELECT']; // ['SELECT', 'INSERT', 'UPDATE', 'DELETE']; for MySQL 5.6.3+
protected $showHints = false;
protected $reflection = [];
protected $backtraceExcludePaths = [
'/vendor/laravel/framework/src/Illuminate/Database',
'/vendor/laravel/framework/src/Illuminate/Events',
'/vendor/barryvdh/laravel-debugbar',
];

/**
* @param TimeDataCollector $timeCollector
Expand Down Expand Up @@ -61,6 +66,16 @@ public function setFindSource($value, array $middleware)
$this->middleware = $middleware;
}

/**
* Set additional paths to exclude from the backtrace
*
* @param array $excludePaths Array of file paths to exclude from backtrace
*/
public function mergeBacktraceExcludePaths(array $excludePaths)
{
$this->backtraceExcludePaths = array_merge($this->backtraceExcludePaths, $excludePaths);
}

/**
* Enable/disable the EXPLAIN queries
*
Expand Down Expand Up @@ -272,15 +287,9 @@ protected function parseTrace($index, array $trace)
*/
protected function fileIsInExcludedPath($file)
{
$excludedPaths = [
'/vendor/laravel/framework/src/Illuminate/Database',
'/vendor/laravel/framework/src/Illuminate/Events',
'/vendor/barryvdh/laravel-debugbar',
];

$normalizedPath = str_replace('\\', '/', $file);

foreach ($excludedPaths as $excludedPath) {
foreach ($this->backtraceExcludePaths as $excludedPath) {
if (strpos($normalizedPath, $excludedPath) !== false) {
return true;
}
Expand Down
5 changes: 5 additions & 0 deletions src/LaravelDebugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ function ($level, $message = null, $context = null) use ($logger) {
$queryCollector->setFindSource(true, $middleware);
}

if ($this->app['config']->get('debugbar.options.db.backtrace_exclude_paths')) {
$excludePaths = $this->app['config']->get('debugbar.options.db.backtrace_exclude_paths');
$queryCollector->mergeBacktraceExcludePaths($excludePaths);
}

if ($this->app['config']->get('debugbar.options.db.explain.enabled')) {
$types = $this->app['config']->get('debugbar.options.db.explain.types');
$queryCollector->setExplainSource(true, $types);
Expand Down

0 comments on commit 34f6b96

Please sign in to comment.