Transactions may optionally contain spans, which measure an individual operation within a transaction process.
$span = Apm::newSpan('fetch-config');
// ...
// ...
$span->finish();
Spans may also have child spans of their own
$span = Apm::newSpan('fetch-config');
// ...
$childSpan = $span->newChildSpan('process-config`');
// ...
$childSpan->finish();
// ...
$span->finish();
Similar to transactions, a spans start time is set to when it is created by default, but may be adjusted.
// start time for span set to when newSpan is called
$span = Apm::newSpan('fetch-config');
// custom start time, set as unix timestamp in milliseconds
$time = microtime(true) * 1000;
$span->setStartTime($time);
If a span never calls finish on it's own, the end time will be set when the parent transaction has finish called.
$span = Apm::newSpan('fetch-config');
// $span->finish() never called , so the end time will be set below when finish() is called on the transaction
Apm::finish();
Otherwise, a span may call finish
or setEndTime
which will not be overwritten when the parent transaction is finished.
Spans can be marked as "database" calls with specific meta properties
$span = Apm::newSpan('fetch-config');
$span->database()
->isReadOperation() // or isWriteOperation()
->setName('mysql-01')
->setQuery('SELECT * FROM config');
Any key/value pair may be set to pass custom metadata for spans
$span = Apm::newSpan('fetch-config');
$span->tags()->set('type', 'json');