According to https://cloud.google.com/trace/docs/setup/php, App Engine flexible environment for PHP can run a daemon that sends trace spans to Stackdriver in the background rather than as part of the request processing (which could cause increased response latency).
I am running Kubernetes Engine, but would still like to send trace requests in the background. Therefore:
Stackdriver Trace with Google Cloud Run seems to cover a similar topic, but does not address how to run the daemon manually.
In case anyone else is looking for this, I was able to run the batch daemon as follows:
sudo -u www-data vendor/bin/google-cloud-batch daemon
Note that the daemon itself must be run as the same user as your “serving” PHP processes in order to access SysV memory shared between both, hence the sudo
. You will also need the PHP sysv and pcntl extensions enabled.