Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/sentry/src/Tracing/Aspect/AmqpProducerAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use PhpAmqpLib\Wire\AMQPTable;
use Sentry\State\Scope;
use Sentry\Tracing\SpanContext;
use Sentry\Util\SentryUid;

use function FriendsOfHyperf\Sentry\trace;

Expand Down Expand Up @@ -73,7 +74,7 @@ protected function handleProduceMessage(ProceedingJoinPoint $proceedingJoinPoint
}
}

$messageId = uniqid('amqp_', true);
$messageId = SentryUid::generate();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

AMQP:显式字符串化 message_id

为避免 headers/Span data 中的类型不一致与潜在序列化问题,建议强转为 string。

请修改为:

-        $messageId = SentryUid::generate();
+        $messageId = (string) SentryUid::generate();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$messageId = SentryUid::generate();
$messageId = (string) SentryUid::generate();
🤖 Prompt for AI Agents
In src/sentry/src/Tracing/Aspect/AmqpProducerAspect.php around line 77, the
generated message ID is assigned without guaranteeing a string type; explicitly
cast the result of SentryUid::generate() to a string (e.g., (string)
SentryUid::generate()) and ensure any place that sets the AMQP header message_id
uses that string value so headers/Span data remain consistently string-typed for
serialization.

$destinationName = implode(', ', (array) $routingKey);
$bodySize = strlen($producerMessage->payload());

Expand Down
3 changes: 2 additions & 1 deletion src/sentry/src/Tracing/Aspect/AsyncQueueJobMessageAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Hyperf\Di\Aop\ProceedingJoinPoint;
use Sentry\State\Scope;
use Sentry\Tracing\SpanContext;
use Sentry\Util\SentryUid;

use function FriendsOfHyperf\Sentry\trace;
use function Hyperf\Support\with;
Expand Down Expand Up @@ -76,7 +77,7 @@ public function handlePush(ProceedingJoinPoint $proceedingJoinPoint)

/** @var \Hyperf\AsyncQueue\Driver\Driver $driver */
$driver = $proceedingJoinPoint->getInstance();
$messageId = method_exists($job, 'getId') ? $job->getId() : uniqid('async_queue_', true);
$messageId = method_exists($job, 'getId') ? $job->getId() : SentryUid::generate();
$destinationName = Context::get('sentry.messaging.destination.name', 'default');
$bodySize = (fn ($job) => strlen($this->packer->pack($job)))->call($driver, $job);
$data = [
Expand Down
5 changes: 3 additions & 2 deletions src/sentry/src/Tracing/Aspect/KafkaProducerAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use longlang\phpkafka\Protocol\RecordBatch\RecordHeader;
use Sentry\State\Scope;
use Sentry\Tracing\SpanContext;
use Sentry\Util\SentryUid;

use function FriendsOfHyperf\Sentry\trace;

Expand Down Expand Up @@ -54,7 +55,7 @@ public function process(ProceedingJoinPoint $proceedingJoinPoint)

protected function sendAsync(ProceedingJoinPoint $proceedingJoinPoint)
{
$messageId = uniqid('kafka_', true);
$messageId = SentryUid::generate();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

sendAsync:统一字符串化 message_id

避免类型/序列化差异,建议显式 (string)。

请修改为:

-        $messageId = SentryUid::generate();
+        $messageId = (string) SentryUid::generate();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$messageId = SentryUid::generate();
$messageId = (string) SentryUid::generate();
🤖 Prompt for AI Agents
In src/sentry/src/Tracing/Aspect/KafkaProducerAspect.php around line 58, the
generated message ID is assigned without ensuring it is a string; update the
assignment to explicitly cast the result of SentryUid::generate() to string so
message_id is always a string (e.g., $messageId = (string)
SentryUid::generate();), ensuring consistent typing/serialization for sendAsync.

$destinationName = $proceedingJoinPoint->arguments['keys']['topic'] ?? 'unknown';
$bodySize = strlen($proceedingJoinPoint->arguments['keys']['value'] ?? '');

Expand Down Expand Up @@ -107,7 +108,7 @@ function (Scope $scope) use ($proceedingJoinPoint, $messages) {
$carrier = Carrier::fromSpan($span)
->with([
'publish_time' => microtime(true),
'message_id' => uniqid('kafka_', true),
'message_id' => SentryUid::generate(),
'destination_name' => $this->getTopic(),
'body_size' => strlen((string) $this->getValue()),
]);
Expand Down