定制 new999day/opentelemetry-auto-ext-amqp 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

new999day/opentelemetry-auto-ext-amqp

最新稳定版本:v1.0

Composer 安装命令:

composer require new999day/opentelemetry-auto-ext-amqp

包简介

OpenTelemetry auto-instrumentation for ext-amqp

README 文档

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

统计信息

  • 总下载量: 7.37k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2024-05-03