Correlating with an Upstream Service

If you have a distributed business transaction in which a tier needs to correlate with an upstream service that is not an entry point supported by the PHP Agent, you can maintain transaction correlation using appdynamics_continue_transaction() in the downstream tier, passing it the correlation header from the service.

Transaction Correlation

You need to extract the correlation header from the service as shown in the following sample. The sample function extracts the correlation header from each message in an AMQP message queue and passes it to appdynamics_continue_transaction().

After processing the message, it calls appdynamics_end_transaction(), which ends the continuation of the transaction on the calling tier. The appdynamics_end_transaction() call does not end the entire distributed transaction in the case where that tier makes a distributed call to another downstream tier.

function amqp_receive($exchangeName, $routingKey, $queueName) {
$amqpConnection = amqp_connection();
$channel = new AMQPChannel($amqpConnection);
$queue = new AMQPQueue($channel);
$queue->setName($queueName);
$queue->bind($exchangeName, $routingKey);
while($message = $queue->get()) {
// Extracting the correlation header.
echo("Message #".$message->getDeliveryTag()." '".$message->getBody()."'");
echo("Correlation header: " . $message->getHeader("singularityheader"));
// Passing correlation header to API.
appdynamics_continue_transaction($message->getHeader("singularityheader"));
doStuff($message);
// End transaction.
appdynamics_end_transaction();
}
if(!$amqpConnection->disconnect()) {
throw new Exception("Could not disconnect !");
}
}

If the service is not a supported entry point and you do not do this, the tier will not be correlated with the upstream transaction.