Stackdriver Trace PHP: How to send spans in the background?

1/22/2020

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:

  1. Is it possible to run that batch daemon myself?
  2. Out of curiosity, how does the Stackdriver PHP Exporter pass these spans to the daemon? I tried to search for that in the source code, but could not find out how it is done.
  3. If #1 is not possible, is there another way to perform span sending in the background?

Stackdriver Trace with Google Cloud Run seems to cover a similar topic, but does not address how to run the daemon manually.

-- MrMage
app-engine-flexible
google-app-engine
google-app-engine-php
google-kubernetes-engine
stackdriver

1 Answer

3/6/2020

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.

-- MrMage
Source: StackOverflow