PHP code example of open-telemetry / opentelemetry-auto-ext-amqp
1. Go to this page and download the library: Download open-telemetry/opentelemetry-auto-ext-amqp library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
open-telemetry / opentelemetry-auto-ext-amqp example snippets
//Create and declare channel
$channel = new AMQPChannel($connection);
$routing_key = 'task_queue';
$callback_func = function(AMQPEnvelope $message, AMQPQueue $q) {
$context = $propagator->extract($message->getHeaders(), ArrayAccessGetterSetter::getInstance());
$tracer = Globals::tracerProvider()->getTracer('my.org.consumer');
// Start a new span that assumes the context that was injected by the producer
$span = $tracer
->spanBuilder('my_queue consume')
->setSpanKind(SpanKind::KIND_CONSUMER)
->setParent($context)
->startSpan();
sleep(sleep(substr_count($message->getBody(), '.')));
$q->ack($message->getDeliveryTag());
$span->end();
};
try{
$queue = new AMQPQueue($channel);
$queue->setName($routing_key);
$queue->setFlags(AMQP_DURABLE);
$queue->declareQueue();
$queue->consume($callback_func);
} catch(AMQPQueueException $ex){
print_r($ex);
} catch(Exception $ex){
print_r($ex);
}
$connection->disconnect();
shell
OTEL_PHP_DISABLED_INSTRUMENTATIONS=ext_amqp