open-telemetry/opentelemetry-auto-ext-amqp

OpenTelemetry auto-instrumentation for ext-amqp

Package info

github.com/opentelemetry-php/contrib-auto-ext-amqp

Homepage

pkg:composer/open-telemetry/opentelemetry-auto-ext-amqp

Statistics

Installs: 286 837

Dependents: 0

Suggesters: 0

Stars: 1

0.0.7 2026-03-24 16:33 UTC

Requires

Suggests

None

Provides

None

Conflicts

None

Replaces

None

Apache-2.0 2c8a0c8dab38433c7326607306afe410134b0b0b

ioinstrumentationtracingopentelemetryopen-telemetryotel

This package is auto-updated.

Last update: 2026-06-08 12:54:34 UTC


README

👁 Releases
👁 Issues
👁 Source
👁 Mirror
👁 Latest Version
👁 Stable

This is a read-only subtree split of https://github.com/open-telemetry/opentelemetry-php-contrib.

OpenTelemetry ext-amqp auto-instrumentation

Please read https://opentelemetry.io/docs/instrumentation/php/automatic/ for instructions on how to install and configure the extension and SDK.

Overview

Auto-instrumentation hooks are registered via composer, and spans will automatically be created for the following methods:

  • AMQPExchange::publish
  • AMQPQueue::ack
  • AMQPQueue::nack
  • AMQPQueue::reject

The instrumentation automatically creates a span for each of the above methods and injects the span context into the message headers. A consumer SHOULD create a span for each message received, extract the span context and can decide to assume the context for processing the message or start a new trace and use trace-links to link the producer with the consumer.

Example

//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();

Full Example: https://github.com/rabbitmq/rabbitmq-tutorials/blob/main/php-amqp/worker.php

Configuration

The extension can be disabled via runtime configuration:

OTEL_PHP_DISABLED_INSTRUMENTATIONS=ext_amqp