Skip to content

Conversation

@huangdijia
Copy link
Contributor

@huangdijia huangdijia commented Sep 3, 2025

Summary by CodeRabbit

  • 新功能
    • 扩展异步队列可观测性:覆盖驱动获取与消息推送,自动捕获队列名、消息ID、消息体大小,并在合适场景附加驱动相关上下文。
  • 改进
    • 更精确的事务起始时间;消费端自动填充系统、目标队列、接收延迟与重试次数等指标,提升端到端追踪质量。
  • 行为变更
    • 异步队列消息推送阶段的异常将直接上抛,便于及时暴露问题。

- Add queue name tracking through driver factory aspect interception
- Include message ID, queue name, and body size in tracing spans
- Track message latency between publish and process
- Enhance carrier packing to support extra metadata
- Remove unused Throwable import
- Set proper start timestamps for queue processing transactions

This enhancement provides better observability for async queue operations
by capturing comprehensive messaging metrics including latency, message
size, and proper queue identification.
@coderabbitai
Copy link

coderabbitai bot commented Sep 3, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

扩展异步队列追踪:拦截范围加入 DriverFactory::getprocess() 分派新增 handleGet()handlePush() 提取 job/queue 信息、计算 messageId/bodySize、丰富 span 数据并通过 CarrierPacker 打包扩展载荷到 Context。监听器在启动事务设定开始时间,结束时解包载荷并填充消息相关数据。

Changes

Cohort / File(s) Summary of changes
AsyncQueue 拦截与追踪扩展
src/sentry/src/Tracing/Aspect/AsyncQueueJobMessageAspect.php
- 在公开拦截列表新增 Hyperf\AsyncQueue\Driver\DriverFactory::get
- process() 新增对 get 的路由至 handleGet()handleGet() 解析队列名写入 Context(sentry.async_queue.name)。
- handlePush() 提取 jobqueueName,生成 messageId,计算 bodySize,写入 trace 数据(message.id/destination/body.size),可附加 RedisDriver 数据,调用 CarrierPacker 打包并将载体存入 Context(TRACE_CARRIER);移除 Throwable 捕获,仅保留 finally 结束 span。
监听器事务数据填充
src/sentry/src/Tracing/Listener/TracingAsyncQueueListener.php
- startTransactioncontinueTrace(...) 后链式 setStartTimestamp(microtime(true))
- finishTransaction:从 Context 取 TRACE_CARRIER,解包后构建 $data(messaging.system/message.id/destination.name/body.size/receive.latency/retry.count),其余流程保持不变。
载体打包扩展
src/sentry/src/Util/CarrierPacker.php
- pack 签名改为 pack(Span $span, array $extra = []),在 JSON 载荷中合并 ...$extra(在 sentry-trace/baggage/traceparent 之后)。
- unpack 未改。

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor App as App Code
  participant DF as DriverFactory
  participant Aspect as AsyncQueueJobMessageAspect
  participant Driver as QueueDriver
  participant Ctx as Context
  participant L as TracingAsyncQueueListener

  rect rgb(245,248,255)
    App->>DF: get(name?)
    activate Aspect
    Aspect->>Ctx: set("sentry.async_queue.name", name or "default")
    deactivate Aspect
    DF-->>App: QueueDriver
  end

  rect rgb(245,255,245)
    App->>Driver: push(job)
    activate Aspect
    Aspect->>Aspect: create span (name=job::class)
    Aspect->>Ctx: get("sentry.async_queue.name")
    Aspect->>Aspect: compute messageId, bodySize
    Aspect->>Aspect: enrich span data (+Redis when applicable)
    Aspect->>Aspect: pack carrier (publish_time, message_id, queue_name, body_size)
    Aspect->>Ctx: set("TRACE_CARRIER", carrier)
    deactivate Aspect
    Driver-->>App: push result
  end

  rect rgb(255,248,245)
    L->>Ctx: get("TRACE_CARRIER")
    L->>L: continueTrace(...).setStartTimestamp(now)
    L->>L: finishTransaction(data from carrier + latency)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • xuanyanwow

Poem

小兔敲键耳朵翘,
队列名儿装口袋,messageId 轻轻咬。
载荷一包蹦又跳,
时间戳在云上笑;
铃铃一声 span 到,
胡萝卜味的 trace 真妙! 🥕✨

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)

Note: Using configuration file /phpstan.neon.dist.
At least one path must be specified to analyse.


📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0a06a13 and ca4cc5b.

📒 Files selected for processing (3)
  • src/sentry/src/Tracing/Aspect/AsyncQueueJobMessageAspect.php (3 hunks)
  • src/sentry/src/Tracing/Listener/TracingAsyncQueueListener.php (2 hunks)
  • src/sentry/src/Util/CarrierPacker.php (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/improve-async-queue-tracing

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@huangdijia huangdijia merged commit 23572ae into main Sep 3, 2025
16 of 17 checks passed
@huangdijia huangdijia deleted the feature/improve-async-queue-tracing branch September 3, 2025 06:26
huangdijia added a commit that referenced this pull request Sep 3, 2025
* feat: improve async queue tracing with detailed messaging metrics

- Add queue name tracking through driver factory aspect interception
- Include message ID, queue name, and body size in tracing spans
- Track message latency between publish and process
- Enhance carrier packing to support extra metadata
- Remove unused Throwable import
- Set proper start timestamps for queue processing transactions

This enhancement provides better observability for async queue operations
by capturing comprehensive messaging metrics including latency, message
size, and proper queue identification.

* feat: add messaging system metadata to async queue tracing

---------

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