Skip to content

Conversation

@huangdijia
Copy link
Contributor

@huangdijia huangdijia commented Sep 28, 2025

Summary

  • Simplifies hub initialization in the Sentry Tracer class by replacing complex tap-based hub cloning with direct SentrySdk::init()
  • Removes unused imports: HubInterface and tap function
  • Maintains the same functionality while improving code readability

Changes

  • Replace tap(clone SentrySdk::getCurrentHub(), fn (HubInterface $hub) => $hub->pushScope()) with simpler SentrySdk::init() and $hub->pushScope()
  • Remove unused imports: Sentry\State\HubInterface and function Hyperf\Tappable\tap
  • Clean up the startTransaction method implementation

Test plan

  • Verify existing Sentry tracing functionality still works
  • Ensure no regression in transaction handling
  • Confirm coroutine context isolation is maintained

Summary by CodeRabbit

  • 新特性
  • Bug 修复
    • 改善启动事务时的上下文管理,降低偶发性错误与追踪中断风险,提升稳定性。
  • 重构
    • 精简追踪器初始化流程,减少不必要依赖,带来更可预测的行为与更轻量的开销。

- Replace complex tap-based hub cloning with direct SentrySdk::init()
- Remove unused imports: HubInterface and tap function
- Simplify startTransaction method while maintaining functionality
- Improve code readability and reduce dependencies
@coderabbitai
Copy link

coderabbitai bot commented Sep 28, 2025

Walkthrough

在 Tracer::startTransaction 中,将原先基于克隆并 setCurrentHub/tap 的 Hub 初始化流程,改为先调用 init() 创建 Hub,再调用 pushScope()。移除未使用的 HubInterface 与 tap 相关导入,其他事务启动与数据填充逻辑保持不变。

Changes

Cohort / File(s) Summary
Tracer Hub 初始化与依赖清理
src/sentry/src/Tracing/Tracer.php
将 Hub 初始化从 setCurrentHub(克隆+tap) 切换为 init()+pushScope();删除未使用的 HubInterface 与 Hyperf tap 导入;保留交易创建与上下文填充的原有流程。

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Caller as 调用方
    participant Tracer as Tracer::startTransaction
    participant Sentry as Sentry SDK
    participant Hub as Hub
    participant Scope as Scope

    Caller->>Tracer: startTransaction(ctx)
    Tracer->>Sentry: init()  // 新:直接初始化 Hub
    Sentry-->>Tracer: Hub
    Tracer->>Hub: pushScope()  // 新:显式入栈作用域
    Tracer->>Hub: startTransaction(ctx)
    Hub-->>Tracer: Transaction
    Tracer-->>Caller: Transaction

    note over Tracer,Hub: 变更点:不再使用 setCurrentHub(克隆+tap),改为 init()+pushScope()
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

小兔挥笔描新径,
Hub 不再克隆行。
init 唤醒推栈影,
事务如流更分明。
代码轻跃春风里,
咔嗒一声万事宁。 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed 提供的标题“refactor(sentry): simplify hub initialization in Tracer”准确概括了该 PR 的核心改动,即在 Tracer 类中重构并简化 Sentry hub 的初始化流程,简洁明了且无多余信息。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/sentry-tracer-simplify-hub-initialization

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

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.

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: 1

📜 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 e8f8e89 and dc7e9ad.

📒 Files selected for processing (1)
  • src/sentry/src/Tracing/Tracer.php (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/sentry/src/Tracing/Tracer.php (1)
src/sentry/class_map/SentrySdk.php (1)
  • SentrySdk (24-65)
⏰ 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.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.3 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.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 huangdijia merged commit d399c85 into main Sep 28, 2025
17 checks passed
@huangdijia huangdijia deleted the refactor/sentry-tracer-simplify-hub-initialization branch September 28, 2025 00:19
huangdijia added a commit that referenced this pull request Sep 28, 2025
- Replace complex tap-based hub cloning with direct SentrySdk::init()
- Remove unused imports: HubInterface and tap function
- Simplify startTransaction method while maintaining functionality
- Improve code readability and reduce dependencies

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