From bb5b0edd785bc454c22fa8c49f6960f8bdd56a72 Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Tue, 21 Oct 2025 12:18:35 +0800 Subject: [PATCH] feat(sentry): add producer identification to AMQP tracing Add producer application name to AMQP message tracing data to enable better observability and message flow tracking across services. This enhancement allows identifying which service produced a message in distributed tracing scenarios. Changes: - Add 'producer' attribute to AMQP producer span data using app_name config - Capture producer information in consumer spans via message carrier - Use 'unknown' as fallback when producer information is unavailable --- src/sentry/src/Tracing/Aspect/AmqpProducerAspect.php | 2 ++ src/sentry/src/Tracing/Listener/EventHandleListener.php | 1 + 2 files changed, 3 insertions(+) diff --git a/src/sentry/src/Tracing/Aspect/AmqpProducerAspect.php b/src/sentry/src/Tracing/Aspect/AmqpProducerAspect.php index fda106f24..4430f6552 100644 --- a/src/sentry/src/Tracing/Aspect/AmqpProducerAspect.php +++ b/src/sentry/src/Tracing/Aspect/AmqpProducerAspect.php @@ -25,6 +25,7 @@ use Sentry\Util\SentryUid; use function FriendsOfHyperf\Sentry\trace; +use function Hyperf\Config\config; /** * @property array{application_headers?:AMQPTable} $properties @@ -86,6 +87,7 @@ function (Scope $scope) use ($proceedingJoinPoint, $producerMessage, $messageId, 'message_id' => $messageId, 'destination_name' => $destinationName, 'body_size' => $bodySize, + 'producer' => config('app_name', 'unknown'), ]); (function () use ($carrier) { $this->properties['application_headers'] ??= new AMQPTable(); diff --git a/src/sentry/src/Tracing/Listener/EventHandleListener.php b/src/sentry/src/Tracing/Listener/EventHandleListener.php index 5b1f235e6..2562a7c9c 100644 --- a/src/sentry/src/Tracing/Listener/EventHandleListener.php +++ b/src/sentry/src/Tracing/Listener/EventHandleListener.php @@ -586,6 +586,7 @@ protected function handleAmqpMessageProcessing(AmqpEvent\BeforeConsume $event): 'messaging.message.body.size' => $carrier?->get('body_size'), 'messaging.message.receive.latency' => $carrier?->has('publish_time') ? (microtime(true) - $carrier->get('publish_time')) : null, 'messaging.message.retry.count' => 0, + 'messaging.message.producer' => $carrier?->get('producer', 'unknown'), 'messaging.destination.name' => $carrier?->get('destination_name') ?: implode(', ', (array) $message->getRoutingKey()), 'messaging.amqp.message.type' => $message->getTypeString(), 'messaging.amqp.message.routing_key' => $message->getRoutingKey(),