Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueryWatcher location can ignore Composer packages #449

Merged
merged 1 commit into from Nov 29, 2018
Merged

QueryWatcher location can ignore Composer packages #449

merged 1 commit into from Nov 29, 2018

Conversation

derekmd
Copy link
Contributor

@derekmd derekmd commented Nov 28, 2018

query-location

When Eloquent models use third-party Composer packages to build queries, the query watcher can log class / line number location for a file outside of the Laravel app/ or resources/views subdirectories.

Example Composer packages:

Find query location in your application code

Example configuration: Changed in a comment below to ['ignore_packages' => true].

Watchers\QueryWatcher::class => [
    'enabled' => env('TELESCOPE_QUERY_WATCHER', true),
    'ignore_packages' => [
        'dimsav/laravel-translatable',
    ],
    'slow' => 100,
],

In addition to ignoring vendor/laravel/*, this will also ignore vendor/dimsav/laravel-translatable file paths (or vendor\dimsav\laravel-translatable on Windows) and go further up the callee stacktrace to find where the query was started.

PHPUnit Coverage

This is difficult to test in PHPUnit since getCallerFromStackTrace() calls PHP function debug_backtrace() that can't be overloaded.

I confirmed this works as intended for two Laravel codebases affected by this.

@derekmd derekmd changed the title QueryWatcher location can ignore vendors QueryWatcher location can ignore Composer vendors Nov 28, 2018
@derekmd derekmd changed the title QueryWatcher location can ignore Composer vendors QueryWatcher location can ignore Composer packages Nov 29, 2018
@themsaid
Copy link
Member

Why not just ignore all paths that start with vendor\?

@derekmd
Copy link
Contributor Author

derekmd commented Nov 29, 2018

I amended the pull request to not require naming the packages:

Watchers\QueryWatcher::class => [
    'enabled' => env('TELESCOPE_QUERY_WATCHER', true),
    'ignore_packages' => true,
    'slow' => 100,
],

For query "Location" shown in the UI,
allow ignoring Composer packages other
than laravel/* so the class/line number
from your app code will be shown
instead.

This would cover 3rd-party query
builder packages such as:

* spatie/laravel-translatable
* dimsav/laravel-translatable
* staudenmeir/eloquent-eager-limit
@taylorotwell taylorotwell merged commit 4a0df7e into laravel:1.0 Nov 29, 2018
@derekmd derekmd deleted the query-location-can-ignore-vendor-packages branch November 29, 2018 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants