Skip to content

Conversation

@huangdijia
Copy link
Contributor

@huangdijia huangdijia commented Oct 21, 2025

Summary

  • Add producer application name to AMQP message tracing data for better observability
  • Enable tracking of message flow across distributed services
  • Capture producer information in both producer and consumer spans

Changes

  • AmqpProducerAspect.php: Add 'producer' attribute to span data using app_name config
  • EventHandleListener.php: Capture and propagate producer information from message carrier

Technical Details

The producer name is extracted from the app_name configuration and included in the AMQP tracing span data. On the consumer side, this information is retrieved from the message carrier and added to the consumer span, allowing for end-to-end visibility of which service produced each message.

Fallback to 'unknown' is used when producer information is unavailable.

Test Plan

  • Verify producer attribute is included in AMQP producer spans
  • Verify producer information is captured in consumer spans
  • Test with configured app_name
  • Test fallback behavior when producer info is missing

Summary by CodeRabbit

发布说明

  • 改进
    • 增强了消息队列操作的追踪数据收集,现在包含生产者应用名称信息,提升可观测性和调试能力。

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
@coderabbitai
Copy link

coderabbitai bot commented Oct 21, 2025

概览

在 AMQP 生产者追踪中增加 'producer' 字段,通过应用配置名称标识消息来源。在 AMQP 消息处理事件监听器中添加对应的追踪数据提取逻辑,将生产者信息传递到跨度标签中以增强可观测性。

变更

类别 / 文件 变更摘要
AMQP 追踪生产者增强
src/sentry/src/Tracing/Aspect/AmqpProducerAspect.php
导入 Hyperf 配置模块,在 AMQP 追踪载体中添加 'producer' 字段,值为应用配置名称(默认 'unknown')
AMQP 消息处理监听器扩展
src/sentry/src/Tracing/Listener/EventHandleListener.php
在 handleAmqpMessageProcessing 方法中新增 'messaging.message.producer' 标签,从追踪载体中提取生产者信息

评估代码审查工作量

🎯 2 (简单) | ⏱️ ~8 分钟

可能相关的 PR

🐰 小小追踪添新字,producer 字段显真身,
配置名字入载体,消息来源一目循,
可观测性更清晰,AMQP 追踪锦上添花。✨

Pre-merge checks and finishing touches

❌ 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed PR标题"feat(sentry): add producer identification to AMQP tracing"与本次变更的主要目标高度吻合。根据代码总结,两个文件的改动都是围绕向AMQP追踪数据中添加生产者标识这一核心目标展开的:AmqpProducerAspect.php中添加了基于应用名称的'producer'字段,EventHandleListener.php中则捕获并传播这个生产者信息。标题清晰、具体,准确概括了本次变更的主要改动,避免了模糊和空泛的表述。
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/sentry-add-producer-to-amqp-tracing

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.31)

At least one path must be specified to analyse.


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 5c7eb7b into main Oct 21, 2025
15 of 17 checks passed
@huangdijia huangdijia deleted the feat/sentry-add-producer-to-amqp-tracing branch October 21, 2025 04:21
huangdijia added a commit that referenced this pull request Oct 21, 2025
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

Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
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 (1)
src/sentry/src/Tracing/Listener/EventHandleListener.php (1)

589-589: 消费者端生产者信息捕获正确!

成功从消息载体中提取生产者信息并添加到追踪数据中,实现了从生产者到消费者的端到端可观测性。空值安全操作符和回退值的使用都很恰当。

可选建议:为保持一致性,可以考虑为 Kafka(第 628-677 行)和 AsyncQueue(第 692-728 行)消息处理也添加类似的生产者追踪功能,以便在整个消息系统中提供统一的可观测性。不过这可以作为后续改进,不影响当前 PR 的功能。

📜 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 0b2be73 and bb5b0ed.

📒 Files selected for processing (2)
  • src/sentry/src/Tracing/Aspect/AmqpProducerAspect.php (2 hunks)
  • src/sentry/src/Tracing/Listener/EventHandleListener.php (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/*/src/**/*.php

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

All component PHP code must use the namespace pattern FriendsOfHyperf{ComponentName}

Files:

  • src/sentry/src/Tracing/Aspect/AmqpProducerAspect.php
  • src/sentry/src/Tracing/Listener/EventHandleListener.php
**/*.php

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.php: Code style must follow PSR-12 and be formatted by PHP-CS-Fixer per .php-cs-fixer.php
Run PHPStan and keep the codebase passing per phpstan.neon.dist

Files:

  • src/sentry/src/Tracing/Aspect/AmqpProducerAspect.php
  • src/sentry/src/Tracing/Listener/EventHandleListener.php
🧬 Code graph analysis (1)
src/sentry/src/Tracing/Listener/EventHandleListener.php (1)
src/sentry/src/Util/Carrier.php (1)
  • get (119-122)
⏰ 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). (12)
  • GitHub Check: Test on PHP 8.1 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.1 with Swoole 5.1.7
  • 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.3 with Swoole 5.1.7
  • GitHub Check: Test on PHP 8.3 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.2 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.1 with Swoole 5.1.7
  • GitHub Check: Test on PHP 8.2 with Swoole 5.1.7
  • GitHub Check: Test on PHP 8.3 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.1 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.3 with Swoole 5.1.7
🔇 Additional comments (2)
src/sentry/src/Tracing/Aspect/AmqpProducerAspect.php (2)

28-28: 导入语句正确!

正确导入了 Hyperf 的 config() 辅助函数,符合框架规范。


90-90: 代码变更正确,已通过验证。

通过代码库搜索确认:

  1. 代码模式已确立:同组件内 RpcAspect.php 也使用了相同的 config('app_name', ...) 模式,说明这是框架内的约定做法。

  2. 防御性设计完善:使用 config('app_name', 'unknown') 的回退机制确保代码的健壮性。即使 app_name 未在配置中定义,也会优雅地使用默认值 'unknown'。

  3. 无需额外配置:Sentry 组件本身无需在其 sentry.php 配置文件中定义 app_name,这是应用层的配置职责,组件只需在使用时提供合理的回退值。

代码变更符合编码规范和框架约定,可以安全合并。

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