Skip to content

Conversation

@huangdijia
Copy link
Contributor

@huangdijia huangdijia commented Sep 9, 2025

Summary

  • Update AmqpProducerAspect to use routing key for destination name instead of exchange
  • Update TracingAmqpListener to use routing key for destination name instead of exchange
  • Improves tracing accuracy by using more specific routing information

Test plan

  • Verify AMQP producer tracing shows correct destination name based on routing key
  • Verify AMQP consumer tracing shows correct destination name based on routing key
  • Test with multiple routing keys to ensure comma-separated format works correctly

Summary by CodeRabbit

  • 新功能
    • 发送与消费路径的目的地名称计算逻辑保持一致,提升追踪数据的可读性与可比性。
  • 缺陷修复
    • 调整 AMQP 追踪的目的地名称:改为基于 routing key(标量直取、数组逗号拼接),不再回退到交换机或默认值。
    • messaging.destination.name 与 Carrier.destination_name 现与实际路由一致;routing key 缺失时为空字符串。

…change

- Update AmqpProducerAspect to use routing key for destination name
- Update TracingAmqpListener to use routing key for destination name
- Improves tracing accuracy by using more specific routing information
@coderabbitai
Copy link

coderabbitai bot commented Sep 9, 2025

Walkthrough

将 AMQP 追踪中 messaging.destination.name 的取值从基于 exchange/默认值,调整为基于 routingKey(标量直取,数组使用逗号连接,空为"")。改动同时应用于消息生产切面与监听器的事务结束逻辑,其他 span 与 AMQP 字段保持不变。

Changes

Cohort / File(s) Summary
AMQP 目的地名称改动
src/sentry/src/Tracing/Aspect/AmqpProducerAspect.php, src/sentry/src/Tracing/Listener/TracingAmqpListener.php
将 messaging.destination.name 与 Carrier.destination_name 从使用 exchange/默认值改为由 routingKey 推导(标量直取,数组以“, ”拼接,空为"");未改动其他 span 字段与注解覆盖逻辑。

Sequence Diagram(s)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • xuanyanwow

Pre-merge checks (2 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed 该 PR 标题“fix(tracing): use routing key for AMQP destination name instead of exchange” 简洁明了地概括了核心变更,即将 AMQP 目标名称从 exchange 改为 routing key,符合最佳实践要求。
Description Check ✅ Passed 当前描述围绕 AmqpProducerAspect 和 TracingAmqpListener 的更新展开,明确说明了使用 routing key 代替 exchange 改善追踪准确性的目的,并提供了相应的测试计划,与更改内容高度相关。

Poem

小兔轻敲路由键,键键成名串相连,
交换不再作后援,目的今日更分明。
脚步轻,踪迹清,
追踪一线穿云行。
(=^·^=)🪄

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 PHPStan (2.1.17)

At least one path must be specified to analyse.

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
		  - name: "Undocumented Breaking Changes"
			  mode: "warning"
			  instructions: |
				  Flag potential breaking changes that are not documented:
				  1. Identify changes to public APIs/exports, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints (including removed/renamed items and changes to types, required params, return values, defaults, or behavior).
				  2. Ignore purely internal/private changes (e.g., code not exported from package entry points or marked internal).
				  3. Verify documentation exists: a "Breaking Change" section in the PR description and updates to CHANGELOG.md.

Please share your feedback with us on this Discord post.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/amqp-destination-name-routing-key

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@huangdijia huangdijia merged commit ed184ea into main Sep 9, 2025
16 of 17 checks passed
@huangdijia huangdijia deleted the fix/amqp-destination-name-routing-key branch September 9, 2025 02:41
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/sentry/src/Tracing/Listener/TracingAmqpListener.php (1)

112-112: routingKey 作为 destination.name 的回退实现 OK,但建议过滤空值并确认空字符串是否符合观测规范

当前 (array)$message->getRoutingKey()null 时会变成空数组,implode 返回空字符串。这与 PR 目标一致,但可能在可观测维度上产生“空值”标签,影响聚合/看板。建议过滤 null/空串,并确认空字符串是否被 Sentry 接受且不会造成查询困扰。

可在一行内完成过滤与字符串化:

-            'messaging.destination.name' => $carrier?->get('destination_name') ?: implode(', ', (array) $message->getRoutingKey()),
+            'messaging.destination.name' => $carrier?->get('destination_name')
+                ?: implode(', ', array_map('strval', array_filter((array) $message->getRoutingKey(), static fn($v) => $v !== null && $v !== ''))),

需要你验证:

  • 目标环境中是否允许 messaging.destination.name 为空字符串;若不允许,是否应改为占位值如 "(empty)"
  • 多 routingKey 场景使用 ", " 连接是否会引入高基数字段,影响事件卡片聚合。
src/sentry/src/Tracing/Aspect/AmqpProducerAspect.php (1)

88-88: destination_name 从 exchange 切换为 routingKey:建议过滤空值并标准化输出,避免携带空元素

为稳健起见,过滤 null/空串并统一字符串化,避免出现 ", , ""0"/false 等非预期片段;同时与 Listener 的实现保持一致。

-        $destinationName = implode(', ', (array) $routingKey);
+        $destinationName = implode(
+            ', ',
+            array_map('strval', array_filter((array) $routingKey, static fn($v) => $v !== null && $v !== ''))
+        );

请同时确认:

  • 去除 exchange 作为回退是否需要在变更日志中标注潜在看板维度变更(基数可能上升,且维度名称值集合变化)。
  • 生产端写入的 destination_name 与消费端回读并回退到 routingKey 的逻辑在所有路径下保持一致(含注解覆写与多 key)。
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 112173a and 0d45753.

📒 Files selected for processing (2)
  • src/sentry/src/Tracing/Aspect/AmqpProducerAspect.php (1 hunks)
  • src/sentry/src/Tracing/Listener/TracingAmqpListener.php (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Test on PHP 8.3 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.3 with Swoole 5.1.7
  • GitHub Check: Test on PHP 8.1 with Swoole 5.1.7
  • GitHub Check: Test on PHP 8.1 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.2 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.2 with Swoole 5.1.7
  • GitHub Check: Test on PHP 8.1 with Swoole 5.1.7
  • GitHub Check: Test on PHP 8.3 with Swoole 5.1.7
  • GitHub Check: Test on PHP 8.2 with Swoole 5.1.7

huangdijia added a commit that referenced this pull request Sep 9, 2025
…change (#903)

- Update AmqpProducerAspect to use routing key for destination name
- Update TracingAmqpListener to use routing key for destination name
- Improves tracing accuracy by using more specific routing information

Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants