scoutapp / scout-apm-laravel

ScoutAPM PHP Agent for the Laravel Framework
MIT License
22 stars 12 forks source link

Feature request: support instrumenting "artisan" commands #54

Closed liam-wiltshire closed 2 years ago

liam-wiltshire commented 4 years ago

At the moment, Scout will not send up data for artisan commands - as far as I can tell the two ways that scout will send data are when triggered by middleware, or when triggered by a queue.

If you have 'regular' artisan commands, then no data will be sent up to scout, however it is still instrumenting database queries. The memory footprint of this is pretty small, so it's not a major drama, however we have a few artisan commands that run as long running processes (essentially a daemon that checks for certain things), and as such because they have no exit-point for scout, the DB spans just continue to increase. I guess the same would happen if someone had disabled queue instrumentation?

I guess longer term it'd be great for scout to instrument artisan commands as it does with events and http requests, but otherwise I wonder if it's possible to have a check, and only instrument DB queries if there is an active request or something?

asgrim commented 4 years ago

Nice suggestion - we'll have a look into this, thank you! :+1:

asgrim commented 2 years ago

@liam-wiltshire Support for instrumenting artisan commands has been added in scoutapp/scout-apm-php:8.6.0 :tada:

If you wish to disable this behaviour, you have a couple of options:

Also to note, if you explicitly want to disable the scoutapm extension from collecting data, but still leave the PHP library performing instrumentation, you can call:

if (function_exists('scoutapm_enable_instrumentation')) {
    scoutapm_enable_instrumentation(false);
}

to disable the extension. This will leave the scoutapp/scout-apm-php library monitoring, but the PHP extension scoutapm will not not collect any data (e.g. on DB queries, file operations etc.)